Code

utils dbi + unixsock: Pass user-data object to data processing callbacks.
[sysdb.git] / src / include / utils / dbi.h
index 2371286abe5e3953f2b208ed0fd0518939f5bc17..b910b977551558e97dc77105b631acc70412044d 100644 (file)
 #ifndef SC_UTILS_DBI_H
 #define SC_UTILS_DBI_H 1
 
-#include "utils/time.h"
+#include "core/object.h"
+#include "utils/data.h"
 
-#include <inttypes.h>
 #include <stddef.h>
 
+/* translate libdbi types to syscollector types */
+#define DBI_TYPE_TO_SC(dt) \
+       (((dt) == DBI_TYPE_INTEGER) \
+               ? SC_TYPE_INTEGER \
+               : ((dt) == DBI_TYPE_DECIMAL) \
+                       ? SC_TYPE_DECIMAL \
+                       : ((dt) == DBI_TYPE_STRING) \
+                               ? SC_TYPE_STRING \
+                               : ((dt) == DBI_TYPE_DATETIME) \
+                                       ? SC_TYPE_DATETIME \
+                                       : ((dt) == DBI_TYPE_BINARY) \
+                                               ? SC_TYPE_BINARY : 0)
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/*
- * sc_dbi_data_t:
- * A datum retrieved from a single field of a query result row.
- *
- * The string and binary objects are managed by libdbi, thus, they must not be
- * freed or modified. If you want to keep them, make sure to make a copy.
- */
-typedef struct {
-       int type;
-       union {
-               int64_t     integer;  /* DBI_TYPE_INTEGER */
-               double      decimal;  /* DBI_TYPE_DECIMAL */
-               const char *string;   /* DBI_TYPE_STRING  */
-               sc_time_t   datetime; /* DBI_TYPE_DATETIME */
-               struct {
-                       size_t length;
-                       const unsigned char *datum;
-               } binary;             /* DBI_TYPE_BINARY */
-       } data;
-} sc_dbi_data_t;
-
 struct sc_dbi_options;
 typedef struct sc_dbi_options sc_dbi_options_t;
 
 struct sc_dbi_client;
 typedef struct sc_dbi_client sc_dbi_client_t;
 
-typedef int (*sc_dbi_data_cb)(sc_dbi_client_t *, size_t, sc_dbi_data_t *);
+typedef int (*sc_dbi_data_cb)(sc_dbi_client_t *,
+               size_t, sc_data_t *, sc_object_t *);
 
 /*
  * sc_dbi_options_t:
@@ -142,7 +135,7 @@ sc_dbi_client_connect(sc_dbi_client_t *client);
  */
 int
 sc_dbi_exec_query(sc_dbi_client_t *client, const char *query,
-               sc_dbi_data_cb callback, int n, ...);
+               sc_dbi_data_cb callback, sc_object_t *user_data, int n, ...);
 
 /*
  * sc_dbi_client_destroy: