erlang plugin: Have "send_error" free the *entire* term.
[collectd.git] / src / dbi.c
index ee43602..ce4cd02 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -126,10 +126,19 @@ static int cdbi_result_get_field (dbi_result res, /* {{{ */
     else
       sstrncpy (buffer, value, buffer_size);
   }
+  /* DBI_TYPE_BINARY */
+  /* DBI_TYPE_DATETIME */
   else
   {
-    ERROR ("dbi plugin: cdbi_result_get: Don't know how to handle "
-        "source type %hu.", src_type);
+    const char *field_name;
+
+    field_name = dbi_result_get_field_name (res, index);
+    if (field_name == NULL)
+      field_name = "<unknown>";
+
+    ERROR ("dbi plugin: Column `%s': Don't know how to handle "
+        "source type %hu.",
+        field_name, src_type);
     return (-1);
   }
 
@@ -356,7 +365,8 @@ static int cdbi_config (oconfig_item_t *ci) /* {{{ */
   {
     oconfig_item_t *child = ci->children + i;
     if (strcasecmp ("Query", child->key) == 0)
-      udb_query_create (&queries, &queries_num, child);
+      udb_query_create (&queries, &queries_num, child,
+          /* callback = */ NULL, /* legacy mode = */ 0);
     else if (strcasecmp ("Database", child->key) == 0)
       cdbi_config_add_database (child);
     else
@@ -712,14 +722,25 @@ static int cdbi_read_database (cdbi_database_t *db) /* {{{ */
   int success;
   int status;
 
+  unsigned int db_version;
+
   status = cdbi_connect_database (db);
   if (status != 0)
     return (status);
   assert (db->connection != NULL);
 
+  db_version = dbi_conn_get_engine_version (db->connection);
+  /* TODO: Complain if `db_version == 0' */
+
   success = 0;
   for (i = 0; i < db->queries_num; i++)
   {
+    /* Check if we know the database's version and if so, if this query applies
+     * to that version. */
+    if ((db_version != 0)
+        && (udb_query_check_version (db->queries[i], db_version) == 0))
+      continue;
+
     status = cdbi_read_database_query (db, db->queries[i]);
     if (status == 0)
       success++;