]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/dbi.c
Fix sqlite.c typo that fails build
[bacula/bacula] / bacula / src / cats / dbi.c
index f3c360ad7195363865fafa8d5de1f596b623ce25..78d1e330c293939360064a692ac236c738a0081a 100644 (file)
@@ -172,7 +172,6 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char
    }
    mdb->db_type        = db_type;
    mdb->db_port        = db_port;
-   mdb->have_insert_id = TRUE;
    mdb->errmsg         = get_pool_memory(PM_EMSG); /* get error message buffer */
    *mdb->errmsg        = 0;
    mdb->cmd            = get_pool_memory(PM_EMSG); /* get command buffer */
@@ -399,6 +398,9 @@ db_close_database(JCR *jcr, B_DB *mdb)
    V(mutex);
 }
 
+void db_check_backend_thread_safe()
+{ }
+
 void db_thread_cleanup()
 { }
 
@@ -1230,7 +1232,7 @@ char *my_dbi_getvalue(dbi_result *result, int row_number, unsigned int column_nu
    return buf;
 }
 
-int my_dbi_sql_insert_id(B_DB *mdb, char *table_name)
+static int my_dbi_sequence_last(B_DB *mdb, const char *table_name)
 {
    /*
     Obtain the current value of the sequence that
@@ -1250,8 +1252,8 @@ int my_dbi_sql_insert_id(B_DB *mdb, char *table_name)
     everything else can use the PostgreSQL formula.
    */
 
-   char      sequence[30];
-   uint64_t    id = 0;
+   char sequence[30];
+   uint64_t id = 0;
 
    if (mdb->db_type == SQL_TYPE_POSTGRESQL) {
 
@@ -1273,6 +1275,25 @@ int my_dbi_sql_insert_id(B_DB *mdb, char *table_name)
    return id;
 }
 
+int my_dbi_insert_autokey_record(B_DB *mdb, const char *query, const char *table_name)
+{
+   /*
+    * First execute the insert query and then retrieve the currval.
+    */
+   if (my_dbi_query(mdb, query)) {
+      return 0;
+   }
+
+   mdb->num_rows = sql_affected_rows(mdb);
+   if (mdb->num_rows != 1) {
+      return 0;
+   }
+
+   mdb->changes++;
+
+   return my_dbi_sequence_last(mdb, table_name);
+}
+
 #ifdef HAVE_BATCH_FILE_INSERT
 const char *my_dbi_batch_lock_path_query[5] = {
    /* Mysql */