From: erkan kolemen <erkankolemen@yahoo.com>
To: pgsql-interfaces@postgresql.org
Subject: PGExec returns error without any comment
Date: Thu, 28 Sep 2006 05:16:10 -0700 (PDT)
Message-ID: <20060928121611.21391.qmail@web58304.mail.re3.yahoo.com> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: erkankolemen@yahoo.com
Subject: Re: PGExec returns error without any comment
In-Reply-To: <20060928121611.21391.qmail@web58304.mail.re3.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox