Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 658839FB35F for ; Thu, 28 Sep 2006 15:33:16 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 79928-10 for ; Thu, 28 Sep 2006 15:33:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web58308.mail.re3.yahoo.com (web58308.mail.re3.yahoo.com [68.142.236.161]) by postgresql.org (Postfix) with SMTP id 9EFE59FA3B0 for ; Thu, 28 Sep 2006 15:33:10 -0300 (ADT) Received: (qmail 11636 invoked by uid 60001); 28 Sep 2006 18:33:09 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=jn8wDTWbrBZ+Lj3Z1GEFU8d/RyB3/DWL8O/Xd42/R5ymHmGX+PwQyBQ/fVGqFmc1wKP7tL5W9snlmdpU+J9oOzC8u0t0Svcvgw3yEvo27qYZGOBO3bOBY1xuEABQuot0YZDQ9vR8vL3vn3dyOrzHZ0zPFzlJmP6DOcA5F5OplAc= ; Message-ID: <20060928183309.11634.qmail@web58308.mail.re3.yahoo.com> Received: from [88.247.172.183] by web58308.mail.re3.yahoo.com via HTTP; Thu, 28 Sep 2006 11:33:09 PDT Date: Thu, 28 Sep 2006 11:33:09 -0700 (PDT) From: erkan kolemen Subject: Re: PGExec returns error without any comment To: pgsql-interfaces@postgresql.org In-Reply-To: <20060928123620.GA1345@alamut> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-477666476-1159468389=:10532" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=4.098 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, HTML_30_40, HTML_MESSAGE, RAZOR2_CF_RANGE_51_100, RAZOR2_CF_RANGE_E8_51_100, RAZOR2_CHECK X-Spam-Level: **** X-Archive-Number: 200609/37 X-Sequence-Number: 6282 --0-477666476-1159468389=:10532 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Thanks, That was the problem! Volkan YAZICI 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. --0-477666476-1159468389=:10532 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Thanks,

That was the problem!

Volkan YAZICI <yazicivo@ttnet.net.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. --0-477666476-1159468389=:10532--