Need help with libpq and PQexec

Started by Juan Backsonover 16 years ago3 messagesgeneral
Jump to latest
#1Juan Backson
juanbackson@gmail.com

Hi,
In my source code, I have:

res = PQexec(conn,"select * from resource");
if(PQresultStatus(res) != PGRES_COMMAND_OK){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR,"PQexec
failed:%s\n",PQerrorMessage(conn));
PQclear(res);
return NULL;
}
PQclear(res);

When it is executed, I am getting PGexec failed error , but the return value
of PQerrorMessage(conn) is empty.

Does anyone know why?

Thanks,
JB

#2Juan Backson
juanbackson@gmail.com
In reply to: Juan Backson (#1)
Re: Need help with libpq and PQexec[RESOLVEd]

I used if (PQresultStatus(res) != PGRES_TUPLES_OK) and it is fine now.

Thanks,
JB

On Tue, Aug 11, 2009 at 3:35 PM, Juan Backson <juanbackson@gmail.com> wrote:

Show quoted text

Hi,
In my source code, I have:

res = PQexec(conn,"select * from resource");
if(PQresultStatus(res) != PGRES_COMMAND_OK){
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR,"PQexec
failed:%s\n",PQerrorMessage(conn));
PQclear(res);
return NULL;
}
PQclear(res);

When it is executed, I am getting PGexec failed error , but the return
value of PQerrorMessage(conn) is empty.

Does anyone know why?

Thanks,
JB

#3David Wilson
david.t.wilson@gmail.com
In reply to: Juan Backson (#1)
Re: Need help with libpq and PQexec

On Tue, Aug 11, 2009 at 3:35 AM, Juan Backson<juanbackson@gmail.com> wrote:

PGRES_COMMAND_OK

You want PGRES_TUPLES_OK for a select statement. You're not getting an
actual failure- you're checking for the wrong status.

--
- David T. Wilson
david.t.wilson@gmail.com