I'm sorry, the patch was for cvs version ... there were c style changes since libzdb-2.1.
In the attachment is the new patch for libzdb-2.1
Martin
Paul J Stevens wrote:
Martin,
your patch didn't quit apply to libzdb-2.1 but I'll test it and include it with the debian package. Is the cvs repo for libzdb publicly accessible?
you should modify your code using TRY-CATCH-END_TRY this way:
I know, and I'm working on that right now.
thanks for the fix.
Index: src/db/postgresql/PostgresqlConnection.c =================================================================== RCS file: /cvsroot/libzdb/src/db/postgresql/PostgresqlConnection.c,v retrieving revision 1.13 retrieving revision 1.17 diff -u -r1.13 -r1.17 --- src/db/postgresql/PostgresqlConnection.c 3 Jan 2008 17:26:05 -0000 1.13 +++ src/db/postgresql/PostgresqlConnection.c 3 Mar 2008 22:34:30 -0000 1.17 @@ -40,7 +40,7 @@ /** * Implementation of the Connection/Strategy interface for postgresql. * - * @version $Id: PostgresqlConnection.c,v 1.13 2008/01/03 17:26:05 hauk Exp $ + * @version $Id: PostgresqlConnection.c,v 1.17 2008/03/03 22:34:30 martinp Exp $ * @file */
@@ -48,7 +48,7 @@ /* ----------------------------------------------------------- Definitions */
-const struct conop postgresqlconops= { +const struct conop postgresqlconops = { "postgresql", PostgresqlConnection_new, PostgresqlConnection_free, @@ -98,13 +98,13 @@ PGconn *db; assert(url); assert(error); - if(! (db= doConnect(url, error))) + if (! (db = doConnect(url, error))) return NULL; NEW(C); - C->db= db; - C->res= NULL; - C->url= url; - C->sb= StringBuffer_new(""); + C->db = db; + C->res = NULL; + C->url = url; + C->sb = StringBuffer_new(""); return C; }
@@ -120,13 +120,13 @@
void PostgresqlConnection_setQueryTimeout(T C, int ms) { assert(C); - C->timeout= ms; + C->timeout = ms; }
void PostgresqlConnection_setMaxRows(T C, int max) { assert(C); - C->maxRows= max; + C->maxRows = max; }
@@ -140,8 +140,8 @@ int PostgresqlConnection_beginTransaction(T C) { PGresult *res; assert(C); - res= PQexec(C->db, "BEGIN TRANSACTION;"); - C->lastError= PQresultStatus(res); + res = PQexec(C->db, "BEGIN TRANSACTION;"); + C->lastError = PQresultStatus(res); PQclear(res); return (C->lastError == PGRES_COMMAND_OK); } @@ -150,8 +150,8 @@ int PostgresqlConnection_commit(T C) { PGresult *res; assert(C); - res= PQexec(C->db, "COMMIT TRANSACTION;"); - C->lastError= PQresultStatus(res); + res = PQexec(C->db, "COMMIT TRANSACTION;"); + C->lastError = PQresultStatus(res); PQclear(res); return (C->lastError == PGRES_COMMAND_OK); } @@ -160,8 +160,8 @@ int PostgresqlConnection_rollback(T C) { PGresult *res; assert(C); - res= PQexec(C->db, "ROLLBACK TRANSACTION;"); - C->lastError= PQresultStatus(res); + res = PQexec(C->db, "ROLLBACK TRANSACTION;"); + C->lastError = PQresultStatus(res); PQclear(res); return (C->lastError == PGRES_COMMAND_OK); } @@ -174,7 +174,7 @@
long long int PostgresqlConnection_rowsChanged(T C) { - int e = FALSE; + int e = false; assert(C); return(Util_parseLLong(PQcmdTuples(C->res), &e) && !e); } @@ -185,8 +185,8 @@ StringBuffer_clear(C->sb); StringBuffer_vappend(C->sb, sql, ap); PQclear(C->res); - C->res= PQexec(C->db, StringBuffer_toString(C->sb)); - C->lastError= PQresultStatus(C->res); + C->res = PQexec(C->db, StringBuffer_toString(C->sb)); + C->lastError = PQresultStatus(C->res); return (C->lastError == PGRES_COMMAND_OK); }
@@ -196,10 +196,10 @@ StringBuffer_clear(C->sb); StringBuffer_vappend(C->sb, sql, ap); PQclear(C->res); - C->res= PQexec(C->db, StringBuffer_toString(C->sb)); - C->lastError= PQresultStatus(C->res); - if(C->lastError == PGRES_TUPLES_OK) { - return ResultSet_new(PostgresqlResultSet_new(C->res, C->maxRows, FALSE), + C->res = PQexec(C->db, StringBuffer_toString(C->sb)); + C->lastError = PQresultStatus(C->res); + if (C->lastError == PGRES_TUPLES_OK) { + return ResultSet_new(PostgresqlResultSet_new(C->res, C->maxRows, false), (Rop_T)&postgresqlrsetops); } return NULL; @@ -223,24 +223,24 @@ p = q = Util_strdup(sql); memset(index, 0, sizeof(index)); index[0] = (long)p; - while(prm1 < maxparam && (p= strchr(p, '?'))) { + while (prm1 < maxparam && (p = strchr(p, '?'))) { prm1++; *p = 0; p++; index[prm1] = (long)p; } - if(!prm1) { + if (!prm1) { stmt = Util_strdup(sql); - } else if(prm1 > maxparam) { + } else if (prm1 > maxparam) { DEBUG("Prepared statement limit is %d parameters\n", maxparam); FREE(q); return NULL; } else { len = strlen(sql) + prm1 * strlen(MAXPARAM + 1); stmt = CALLOC(1, len + 1); - while(prm2 <= prm1) { + while (prm2 <= prm1) { sprintf(stmt + strlen(stmt), "%s", (char *)index[prm2]); - if(prm2 < prm1) + if (prm2 < prm1) sprintf(stmt + strlen(stmt), "$%d", prm2 + 1); prm2++; } @@ -249,9 +249,12 @@ /* Get the unique prepared statement ID */ name = Util_getString("%d", rand()); PQclear(C->res); - C->res = PQprepare(C->db, name, stmt, prm1, NULL); + C->res = PQprepare(C->db, name, stmt, 0, NULL); FREE(stmt); - if(C->lastError == PGRES_COMMAND_OK || C->lastError == PGRES_TUPLES_OK) { + if (C->res && + (C->lastError == PGRES_EMPTY_QUERY || + C->lastError == PGRES_COMMAND_OK || + C->lastError == PGRES_TUPLES_OK)) { return PreparedStatement_new(PostgresqlPreparedStatement_new(C->db, C->maxRows, name, @@ -275,33 +278,33 @@
static PGconn *doConnect(URL_T url, char **error) { -#define ERROR(e) do {*error= Util_strdup(e); goto error;} while(0) +#define ERROR(e) do {*error = Util_strdup(e); goto error;} while (0) int port; - int ssl = FALSE; + int ssl = false; int connectTimeout = SQL_DEFAULT_TCP_TIMEOUT; const char *user, *password, *host, *database, *timeout; char *conninfo; PGconn *db = NULL; - if(!(user= URL_getUser(url))) - if(!(user= URL_getParameter(url, "user"))) + if (!(user = URL_getUser(url))) + if (!(user = URL_getParameter(url, "user"))) ERROR("no username specified in URL"); - if(!(password= URL_getPassword(url))) - if(!(password= URL_getParameter(url, "password"))) + if (!(password = URL_getPassword(url))) + if (!(password = URL_getParameter(url, "password"))) ERROR("no password specified in URL"); - if(!(host= URL_getHost(url))) + if (!(host = URL_getHost(url))) ERROR("no host specified in URL"); - if((port= URL_getPort(url))<=0) + if ((port = URL_getPort(url))<=0) ERROR("no port specified in URL"); - if(!(database= URL_getPath(url))) + if (!(database = URL_getPath(url))) ERROR("no database specified in URL"); else database++; - if(IS(URL_getParameter(url, "use-ssl"), "true")) - ssl= TRUE; - if((timeout= URL_getParameter(url, "connect-timeout"))) { - int e= FALSE; + if (IS(URL_getParameter(url, "use-ssl"), "true")) + ssl = true; + if ((timeout = URL_getParameter(url, "connect-timeout"))) { + int e = false; connectTimeout = Util_parseInt(timeout, &e); - if(connectTimeout<=0 || e) ERROR("invalid connect timeout value"); + if (connectTimeout<=0 || e) ERROR("invalid connect timeout value"); } conninfo = Util_getString(" host='%s'" " port=%d" @@ -321,8 +324,8 @@ ); db = PQconnectdb(conninfo); FREE(conninfo); - if(PQstatus(db) != CONNECTION_OK) { - *error= Util_getString("%s", PQerrorMessage(db)); + if (PQstatus(db) != CONNECTION_OK) { + *error = Util_getString("%s", PQerrorMessage(db)); goto error; } return db;