Browse Source

ckdb - fix nextid breakage

master
kanoi 10 years ago
parent
commit
095402b069
  1. 8
      src/ckdb.c

8
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) tv_t *cd, char *by, char *code, char *inet)
{ {
ExecStatusType rescode; ExecStatusType rescode;
bool conned = false;
PGresult *res; PGresult *res;
char qry[1024]; char qry[1024];
char *params[5]; char *params[5];
@ -1757,6 +1758,11 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment,
"where idname='%s' for update", "where idname='%s' for update",
idname); idname);
if (conn == NULL) {
conn = dbconnect();
conned = true;
}
res = PQexec(conn, qry); res = PQexec(conn, qry);
rescode = PQresultStatus(res); rescode = PQresultStatus(res);
if (!PGOK(rescode)) { if (!PGOK(rescode)) {
@ -1811,6 +1817,8 @@ static int64_t nextid(PGconn *conn, char *idname, int64_t increment,
free(params[n]); free(params[n]);
cleanup: cleanup:
PQclear(res); PQclear(res);
if (conned)
PQfinish(conn);
return lastid; return lastid;
} }

Loading…
Cancel
Save