From: | erkan kolemen <erkankolemen(at)yahoo(dot)com> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: PGExec returns error without any comment |
Date: | 2006-09-28 18:33:09 |
Message-ID: | 20060928183309.11634.qmail@web58308.mail.re3.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
Thanks,
That was the problem!
Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr> wrote: On Sep 28 05:16, erkan kolemen wrote:
> 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);
I'd prefer a
char conninfo[] = "dbname=llist user=yyy password=xxx";
instead of above mess.
> /* 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)
You should be checking for PGRES_TUPLES_OK, not COMMAND_OK.
AFAIU from your name, you're from Turkey. Have you ever heard about
"PostgreSQL ile Programlama" book? You can get it freely from here:
http://www.students.itu.edu.tr/~yazicivo/doc/postgresql-ile-programlama.html
Regards.
---------------------------------
All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Gidlund | 2006-09-29 12:38:43 | Re: Compilations failing |
Previous Message | Bruce Momjian | 2006-09-28 16:52:14 | Re: Extracting client code |