--- src/dm_db.c +++ src/dm_db.c @@ -568,17 +575,26 @@ if (! db_result_next(r)) { /* ignore */ } - // lastRowId is always zero for pgsql tables without OIDs - // or possibly for sqlite after calling executeQuery but - // before calling db_result_next - - if ((id = (uint64_t )Connection_lastRowId(c)) == 0) { // mysql - // but if we're using 'RETURNING id' clauses on inserts - // or we're using the sqlite backend, we can do this + // The old methods of handling results no longer work. + // Use the database driver to determine how to retrieve the resulting + // message id. + switch (db_params.db_driver) + { + case DM_DRIVER_POSTGRESQL: + id = db_result_get_u64(r, 0); // postgresql + break; + + case DM_DRIVER_SQLITE: + case DM_DRIVER_MYSQL: + case DM_DRIVER_ORACLE: + id = (uint64_t) Connection_lastRowId(c); // sqlite, mysql, oracle + break; - if ((id = (uint64_t )Connection_lastRowId(c)) == 0) // sqlite - id = db_result_get_u64(r, 0); // postgresql + default: + TRACE(TRACE_DATABASE, "Unknown driver"); + break; } + assert(id); return id; }