Re: error in code

From: Stephen Powell <stephen_powell(at)optusnet(dot)com(dot)au>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: error in code
Date: 2003-12-11 01:57:44
Message-ID: u3cbsi09z.fsf@privacy.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 10 Dec 2003, ashok(at)kalculate(dot)com wrote:

> I written a code

[...]

Checking for errors is good:

# include <stdio.h>
# include <stdlib.h>
# include <libpq-fe.h>

int main()
{
PGresult *result = NULL;
PGconn *conn = NULL;
int feild;
printf("successful");
conn = PQconnectdb ("ashok");
if (!conn || CONNECTION_BAD == PQstatus(conn)) {
fprintf(stderr, "Connection to database failed.\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
exit(EXIT_FAILURE);
}
result = PQexec (conn, "select * from bill");
if (!result || PGRES_TUPLES_OK != PQresultStatus(result)) {
fprintf(stderr, "select command returned no tuples\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
exit(EXIT_FAILURE);
}
feild = PQntuples (result);
printf("%d",feild);
PQclear (result);
PQfinish (conn);
printf("hello");
return EXIT_SUCCESS;
}

> when i run the a.out it give nothing.

Not even "successful" or "hello" from the printfs?

> plz help me.

Download the programmers manual from here <http://www.postgresql.org/docs/>

--
Stephen Powell

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Bhartendu Maheshwari 2003-12-11 05:03:55 Re: Running Postgres Daemons with same data files
Previous Message Jim Cochrane 2003-12-10 21:56:17 Re: Postrgres data restoration problem