summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ts3db.c16
1 files changed, 10 insertions, 6 deletions
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 <libpq-fe.h>
#include <stdbool.h>
+#include <string.h>
#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,