Code

dbi utils: Use the new _r interface.
[sysdb.git] / src / utils / dbi.c
index c8eb81616454a3078eb768f16b1affd32b81f1d9..de2348e713d34e82924bbf4870d252d186626803 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include "utils/dbi.h"
 #include "utils/error.h"
 
@@ -56,6 +60,7 @@ struct sdb_dbi_client {
        char *database;
 
        dbi_conn conn;
+       dbi_inst inst;
 
        sdb_dbi_options_t *options;
 };
@@ -155,13 +160,8 @@ sdb_dbi_get_data(sdb_dbi_client_t *client, dbi_result res,
                                continue;
 
                status = callback(client, num_fields, data, user_data);
-               for (i = 0; i < num_fields; ++i) {
-                       if ((data[i].type == SDB_TYPE_STRING) && (data[i].data.string))
-                               free(data[i].data.string);
-                       else if ((data[i].type == SDB_TYPE_BINARY)
-                                       && (data[i].data.binary.datum))
-                               free(data[i].data.binary.datum);
-               }
+               for (i = 0; i < num_fields; ++i)
+                       sdb_data_free_datum(&data[i]);
 
                if (status)
                        continue;
@@ -264,6 +264,11 @@ sdb_dbi_client_create(const char *driver, const char *database)
        client->conn = NULL;
        client->options = NULL;
 
+       if (dbi_initialize_r(/* driverdir = */ NULL, &client->inst) < 0) {
+               free(client);
+               return NULL;
+       }
+
        client->driver = strdup(driver);
        client->database = strdup(database);
        if ((! client->driver) || (! client->database)) {
@@ -300,15 +305,15 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client)
                client->conn = NULL;
        }
 
-       driver = dbi_driver_open(client->driver);
+       driver = dbi_driver_open_r(client->driver, client->inst);
        if (! driver) {
                sdb_error_set("dbi: failed to open DBI driver '%s'; "
                                "possibly it's not installed.\n",
                                client->driver);
 
                sdb_error_append("dbi: known drivers:\n");
-               for (driver = dbi_driver_list(NULL); driver;
-                               driver = dbi_driver_list(driver)) {
+               for (driver = dbi_driver_list_r(NULL, client->inst); driver;
+                               driver = dbi_driver_list_r(driver, client->inst)) {
                        sdb_error_append("\t- %s\n", dbi_driver_get_name(driver));
                }
                sdb_error_chomp();
@@ -485,6 +490,8 @@ sdb_dbi_client_destroy(sdb_dbi_client_t *client)
                dbi_conn_close(client->conn);
        client->conn = NULL;
 
+       dbi_shutdown_r(client->inst);
+
        if (client->options)
                sdb_dbi_options_destroy(client->options);
        client->options = NULL;