Skip site navigation (1) Skip section navigation (2)

PGExec returns error without any comment

From: erkan kolemen <erkankolemen(at)yahoo(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: PGExec returns error without any comment
Date: 2006-09-28 12:16:10
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces

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(at)hq src]# ./1
PQExec failed(2):

#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));
                return -1;



        return 0;

Do you Yahoo!?
 Get on board. You're invited to try the new Yahoo! Mail.


pgsql-interfaces by date

Next:From: Michael FuhrDate: 2006-09-28 13:37:41
Subject: Re: PGExec returns error without any comment
Previous:From: Perla SnellDate: 2006-09-27 20:23:01
Subject: unsubscribe

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group