From: erkan kolemen <erkankolemen@yahoo.com>
To: pgsql-interfaces@postgresql.org
Subject: Re: PGExec returns error without any comment
Date: Thu, 28 Sep 2006 11:33:09 -0700 (PDT)
Message-ID: <20060928183309.11634.qmail@web58308.mail.re3.yahoo.com> (raw)
In-Reply-To: <20060928123620.GA1345@alamut>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: erkankolemen@yahoo.com
Subject: Re: PGExec returns error without any comment
In-Reply-To: <20060928183309.11634.qmail@web58308.mail.re3.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox