* by Kern Sibbald, March 2000
*
*/
+/*
+ * This code only compiles against a recent version of libdbi. The current
+ * release found on the libdbi website (0.8.3) won't work for this code.
+ *
+ * You find the libdbi library on http://sourceforge.net/projects/libdbi
+ *
+ * A fairly recent version of libdbi from CVS works, so either make sure
+ * your distribution has a fairly recent version of libdbi installed or
+ * clone the CVS repositories from sourceforge and compile that code and
+ * install it.
+ *
+ * You need:
+ * cvs co :pserver:anonymous@libdbi.cvs.sourceforge.net:/cvsroot/libdbi
+ * cvs co :pserver:anonymous@libdbi-drivers.cvs.sourceforge.net:/cvsroot/libdbi-drivers
+ */
/* The following is necessary so that we do not include
}
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 */
V(mutex);
}
+void db_check_backend_thread_safe()
+{ }
+
void db_thread_cleanup()
{ }
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
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) {
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 */
"BEGIN",
/* SQLite3 */
"BEGIN",
- /* Ingres (TODO) */
+ /* Ingres */
"BEGIN"
};
"BEGIN",
/* SQLite3 */
"BEGIN",
- /* Ingres (TODO) */
+ /* Ingres */
"BEGIN"
};
"INSERT INTO Path (Path)"
" SELECT DISTINCT Path FROM batch"
" EXCEPT SELECT Path FROM Path",
- /* Ingres (TODO) */
+ /* Ingres */
"INSERT INTO Path (Path) "
"SELECT a.Path FROM "
"(SELECT DISTINCT Path FROM batch) AS a "
"INSERT INTO Filename (Name)"
" SELECT DISTINCT Name FROM batch "
" EXCEPT SELECT Name FROM Filename",
- /* Ingres (TODO) */
+ /* Ingres */
"INSERT INTO Filename (Name) "
"SELECT a.Name FROM "
"(SELECT DISTINCT Name FROM batch) as a "