From 095402b069ba4c197b4ed2238e00d962ef416624 Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 12 Aug 2014 00:56:43 +1000 Subject: [PATCH] ckdb - fix nextid breakage --- src/ckdb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ckdb.c b/src/ckdb.c index d21d941e..1f527027 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -1742,6 +1742,7 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment, tv_t *cd, char *by, char *code, char *inet) { ExecStatusType rescode; + bool conned = false; PGresult *res; char qry[1024]; char *params[5]; @@ -1757,6 +1758,11 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment, "where idname='%s' for update", idname); + if (conn == NULL) { + conn = dbconnect(); + conned = true; + } + res = PQexec(conn, qry); rescode = PQresultStatus(res); if (!PGOK(rescode)) { @@ -1811,6 +1817,8 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment, free(params[n]); cleanup: PQclear(res); + if (conned) + PQfinish(conn); return lastid; }