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

Re: PGExec returns error without any comment

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 (view raw or flat)
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.

pgsql-interfaces by date

Next:From: Andreas GidlundDate: 2006-09-29 12:38:43
Subject: Re: Compilations failing
Previous:From: Bruce MomjianDate: 2006-09-28 16:52:14
Subject: Re: Extracting client code

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