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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: PGExec returns error without any comment



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.

Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group