mdb = (B_DB *)malloc(sizeof(B_DB));
memset(mdb, 0, sizeof(B_DB));
mdb->db_name = bstrdup(db_name);
- 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 */
mdb->fields = (SQL_FIELD **)malloc(sizeof(SQL_FIELD) * mdb->ncolumn);
for (i=0; i < sql_num_fields(mdb); i++) {
mdb->fields[i] = (SQL_FIELD *)malloc(sizeof(SQL_FIELD));
+ /* ***FIXME*** it seems to me that this is wrong
+ * fields has lots of items
+ */
if (mdb->result[i] == NULL) {
mdb->fields_defined = false;
free(mdb->fields);
}
}
+int my_sqlite_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_sqlite_query(mdb, query)) {
+ return 0;
+ }
+
+ mdb->num_rows = sql_affected_rows(mdb);
+ if (mdb->num_rows != 1) {
+ return 0;
+ }
+
+ mdb->changes++;
+
+#ifdef HAVE_SQLITE3
+ return sqlite3_last_insert_rowid(mdb->db);
+#else
+ return sqlite_last_insert_rowid(mdb->db);
+#endif
+}
+
#ifdef HAVE_BATCH_FILE_INSERT
const char *my_sqlite_batch_lock_query = "BEGIN";
const char *my_sqlite_batch_unlock_query = "COMMIT";