From 895b47c26ea681c0e09e7c9f468a2934cb6f452b Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 7 Dec 2011 05:08:46 +0100 Subject: fix last inserted id pg insert should return the serial field as last_inserted_id --- ts3db.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ts3db.c') diff --git a/ts3db.c b/ts3db.c index e6e1848..33bc9b0 100644 --- a/ts3db.c +++ b/ts3db.c @@ -1,6 +1,7 @@ #include "ts3db.h" #include #include +#include #define MAX_CONNECTIONS 100 @@ -182,15 +183,18 @@ unsigned long long ts3dbplugin_getlastinsertid(unsigned int connection_nr) { log("getlastinsertid", LOG_DEVELOP); const PGresult *result = get_last_result(connection_nr); - Oid value = PQoidValue(result); - fprintf(stderr, "%llu\n", value); - if (value == InvalidOid) { - log("0", LOG_DEVELOP); - return 0; + if (PQnfields(result) == 1) { + if (strcmp(PQfname(result, 0), "last_inserted_id") == 0) { + const char *count = PQgetvalue(result, 0, 0); + unsigned long long number; + + sscanf(count, "%llu", &number); + return number; + } } - return value; + return 0; } unsigned int ts3dbplugin_open(unsigned int connection_nr, const char* query, -- cgit v1.2.3