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: | 20060928121611.21391.qmail@web58304.mail.re3.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
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(at)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2006-09-28 13:37:41 | Re: PGExec returns error without any comment |
Previous Message | Perla Snell | 2006-09-27 20:23:01 | unsubscribe |