PGExec returns error without any comment - Mailing list pgsql-interfaces

From erkan kolemen
Subject PGExec returns error without any comment
Date
Msg-id 20060928121611.21391.qmail@web58304.mail.re3.yahoo.com
Whole thread Raw
Responses Re: PGExec returns error without any comment  (Michael Fuhr <mike@fuhr.org>)
List pgsql-interfaces
Hi, <br /><br />Following code fails at PQExec. I am using PQerrorMessage() function to print error message but no
output.Error code is 2. What could be the problem with select query? I tried with "drop table" it worked.<br /><br
/>[root@hqsrc]# ./1<br />PQExec failed(2):<br /><br />1.c<br />#include <stdio.h><br />#include
<stdlib.h><br/>#include <string.h><br />#include <errno.h><br />#include <sys/time.h><br
/>#include<libpq-fe.h><br /><br />int main()<br />{<br />        char *conninfo;<br />        PGconn    
*conn;<br/>        PGresult   *res;<br /><br />        /* Prepare connection info */<br />        conninfo = (char *)
malloc(64);<br/>        if (conninfo == NULL) {<br />                fprintf(stderr, "malloc error: %s\n",
strerror(errno));<br/>                return -1;<br />        }<br /><br />        memset(conninfo, 0, 64);<br
/>       strncpy(conninfo, "dbname=llist user=yyy password=xxx", 63);<br /><br />        /* Make a connection to the
database*/<br />        conn = PQconnectdb(conninfo);<br /><br />        /* Check to see that the backend connection
wassuccessfully made */<br />        if (PQstatus(conn) != CONNECTION_OK)<br />        {<br />               
fprintf(stderr,"Connection to database failed: %s", PQerrorMessage(conn));<br />                return -1;<br />       
}<br/><br />        res = PQexec(conn, "select * from lists;");<br />        if (PQresultStatus(res) !=
PGRES_COMMAND_OK)<br/>        {<br />                fprintf(stderr, "PQExec failed(%d): %s\n", PQresultStatus(res),
PQerrorMessage(conn));<br/>                PQclear(res);<br />                return -1;<br />        }<br /><br
/>       PQclear(res);<br /><br />        PQfinish(conn);<br /><br />        return 0;<br />}<br /><br /><p><hr
size="1"/>Do you Yahoo!?<br /> Get on board. <a
href="http://us.rd.yahoo.com/evt=40791/*http://advision.webevents.yahoo.com/mailbeta">You'reinvited</a> to try the new
Yahoo!Mail. 

pgsql-interfaces by date:

Previous
From: Perla Snell
Date:
Subject: unsubscribe
Next
From: Michael Fuhr
Date:
Subject: Re: PGExec returns error without any comment