logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

PGExec returns error without any comment: msg#00026

Subject: PGExec returns error without any comment
Hi,

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.

[root@hq src]# ./1
PQExec failed(2):

1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#include <libpq-fe.h>

int main()
{
        char *conninfo;
        PGconn     *conn;
        PGresult   *res;

        /* Prepare connection info */
        conninfo = (char *) malloc(64);
        if (conninfo == NULL) {
                fprintf(stderr, "malloc error: %s\n", strerror(errno));
                return -1;
        }

        memset(conninfo, 0, 64);
        strncpy(conninfo, "dbname=llist user=yyy password=xxx", 63);

        /* Make a connection to the database */
        conn = PQconnectdb(conninfo);

        /* Check to see that the backend connection was successfully made */
        if (PQstatus(conn) != CONNECTION_OK)
        {
                fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn));
                return -1;
        }

        res = PQexec(conn, "select * from lists;");
        if (PQresultStatus(res) != PGRES_COMMAND_OK)
        {
                fprintf(stderr, "PQExec failed(%d): %s\n", PQresultStatus(res), PQerrorMessage(conn));
                PQclear(res);
                return -1;
        }

        PQclear(res);

        PQfinish(conn);

        return 0;
}


Do you Yahoo!?
Get on board. You're invited to try the new Yahoo! Mail.
<Prev in Thread] Current Thread [Next in Thread>