Code

Renamed the project to SysDB (System DataBase).
[sysdb.git] / src / include / utils / dbi.h
index 0f2a157c28dca42ab965a075e77a126bd94cb7ee..77d004296d333acaefc7460677a246765e182423 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * syscollector - src/include/utils/dbi.h
+ * SysDB - src/include/utils/dbi.h
  * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
  * All rights reserved.
  *
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef SC_UTILS_DBI_H
-#define SC_UTILS_DBI_H 1
+#ifndef SDB_UTILS_DBI_H
+#define SDB_UTILS_DBI_H 1
 
+#include "core/object.h"
 #include "utils/data.h"
 
 #include <stddef.h>
 
-/* translate libdbi types to syscollector types */
+/* translate libdbi types to SysDB types */
 #define DBI_TYPE_TO_SC(dt) \
        (((dt) == DBI_TYPE_INTEGER) \
-               ? SC_TYPE_INTEGER \
+               ? SDB_TYPE_INTEGER \
                : ((dt) == DBI_TYPE_DECIMAL) \
-                       ? SC_TYPE_DECIMAL \
+                       ? SDB_TYPE_DECIMAL \
                        : ((dt) == DBI_TYPE_STRING) \
-                               ? SC_TYPE_STRING \
+                               ? SDB_TYPE_STRING \
                                : ((dt) == DBI_TYPE_DATETIME) \
-                                       ? SC_TYPE_DATETIME \
+                                       ? SDB_TYPE_DATETIME \
                                        : ((dt) == DBI_TYPE_BINARY) \
-                                               ? SC_TYPE_BINARY : 0)
+                                               ? SDB_TYPE_BINARY : 0)
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-struct sc_dbi_options;
-typedef struct sc_dbi_options sc_dbi_options_t;
+struct sdb_dbi_options;
+typedef struct sdb_dbi_options sdb_dbi_options_t;
 
-struct sc_dbi_client;
-typedef struct sc_dbi_client sc_dbi_client_t;
+struct sdb_dbi_client;
+typedef struct sdb_dbi_client sdb_dbi_client_t;
 
-typedef int (*sc_dbi_data_cb)(sc_dbi_client_t *, size_t, sc_data_t *);
+typedef int (*sdb_dbi_data_cb)(sdb_dbi_client_t *,
+               size_t, sdb_data_t *, sdb_object_t *);
 
 /*
- * sc_dbi_options_t:
+ * sdb_dbi_options_t:
  * This object stores DBI connection options (key/value) (e.g. host, dbname,
  * etc.). It may be used to dynamically create the list of options before
  * applying it to some client object.
  */
-sc_dbi_options_t *
-sc_dbi_options_create(void);
+sdb_dbi_options_t *
+sdb_dbi_options_create(void);
 
 int
-sc_dbi_options_add(sc_dbi_options_t *options,
+sdb_dbi_options_add(sdb_dbi_options_t *options,
                const char *key, const char *value);
 
 void
-sc_dbi_options_destroy(sc_dbi_options_t *options);
+sdb_dbi_options_destroy(sdb_dbi_options_t *options);
 
 /*
- * sc_dbi_client_create:
+ * sdb_dbi_client_create:
  * Creates a new DBI client object using the specified DBI / DBD 'driver' and
  * connecting to the specified 'database'.
  *
@@ -82,24 +84,24 @@ sc_dbi_options_destroy(sc_dbi_options_t *options);
  *  - the client object on success
  *  - NULL else
  */
-sc_dbi_client_t *
-sc_dbi_client_create(const char *driver, const char *database);
+sdb_dbi_client_t *
+sdb_dbi_client_create(const char *driver, const char *database);
 
 /*
- * sc_dbi_client_set_options:
+ * sdb_dbi_client_set_options:
  * Apply connection options to an existing client object. This has to be done
- * before actually connecting to the database using sc_dbi_client_connect().
+ * before actually connecting to the database using sdb_dbi_client_connect().
  *
  * Returns:
  *  - 0 on success
  *  - a negative value else
  */
 int
-sc_dbi_client_set_options(sc_dbi_client_t *client,
-               sc_dbi_options_t *options);
+sdb_dbi_client_set_options(sdb_dbi_client_t *client,
+               sdb_dbi_options_t *options);
 
 /*
- * sc_dbi_client_connect:
+ * sdb_dbi_client_connect:
  * Connect to the database using the options registered beforehand.
  *
  * This function may also be used to reconnect to the database.
@@ -109,17 +111,17 @@ sc_dbi_client_set_options(sc_dbi_client_t *client,
  *  - a negative value else
  */
 int
-sc_dbi_client_connect(sc_dbi_client_t *client);
+sdb_dbi_client_connect(sdb_dbi_client_t *client);
 
 /*
- * sc_dbi_exec_query:
+ * sdb_dbi_exec_query:
  * Execute an SQL query on the database. The specified 'callback' will be
  * called for each row returned from the query. If 'n' is a value equal to or
  * greater than zero, it specifies the number of columns that are expected in
  * the query result. For each column, the caller then needs to also specify
  * the requested type (see the DBI_TYPE_* constants). If the number or types
  * do not match, an error will be reported and the query will fail. That is,
- * this allows to let sc_dbi_exec_query() do basic verification of the
+ * this allows to let sdb_dbi_exec_query() do basic verification of the
  * returned values.
  *
  * The callback will receive the client object and an array containing the
@@ -132,21 +134,21 @@ sc_dbi_client_connect(sc_dbi_client_t *client);
  *  - a negative value else
  */
 int
-sc_dbi_exec_query(sc_dbi_client_t *client, const char *query,
-               sc_dbi_data_cb callback, int n, ...);
+sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query,
+               sdb_dbi_data_cb callback, sdb_object_t *user_data, int n, ...);
 
 /*
- * sc_dbi_client_destroy:
+ * sdb_dbi_client_destroy:
  * Disconnect from the database and destroy the client object.
  */
 void
-sc_dbi_client_destroy(sc_dbi_client_t *client);
+sdb_dbi_client_destroy(sdb_dbi_client_t *client);
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
-#endif /* ! SC_UTILS_DBI_H */
+#endif /* ! SDB_UTILS_DBI_H */
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */