[Announce] libzdb 2.1
Martin Pala
martinp at tildeslash.com
Mon Mar 3 23:40:11 CET 2008
Jan-Henrik Haukeland wrote:
>> - I can't use Connection_PreparedStatement on a postgresql
>> connection until I've
>> issued a Connection_executeQuery. Doing so segfaults in libzdb. I've
>> reported
>> this one already, and I can easily work around this.
>
> Its on my TODO list and I hope to have it moved over to Martin's TODO
> list :)
Hi,
the problem should be fixed ... postgresql returned PGRES_EMPTY_QUERY
for PQprepare() whereas libzdb expected PGRES_COMMAND_OK or
PGRES_TUPLES_OK. I have checked the postgresql code and it seems that
PGRES_EMPTY_QUERY is not error in this context - the prepared statement
is processed fine. I have modified the code to check for result (C->res)
of PQprepare() and accept the PGRES_EMPTY_QUERY.
Note that to prevent the uncaught exception like this:
--8<--
Uncaught exception SQLException raised in Connection_prepareStatement at
src/db/Connection.c:294
--8<--
you should modify your code using TRY-CATCH-END_TRY this way:
--8<--
TRY
{
PreparedStatement_T p =
Connection_prepareStatement(con, "SELECT * FROM dbmail_users WHERE
userid=?;");
if (! p)
printf("[%s]", Connection_getLastError(con));
assert(p);
}
CATCH(SQLException)
{
printf("\tResult: prepare statement failed -- %s\n",
Connection_getLastError(con));
}
END_TRY;
--8<--
This way you will get the the error message printed out and the program
won't crash.
The patch is in the cvs and attachment as well.
Cheers,
Martin
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libzdb_pq-preparedstatement.patch
Url: http://www.tildeslash.com/pipermail/libzdb-general/attachments/20080303/c20513bd/attachment.ksh
More information about the libzdb-general
mailing list