Discussion:
error in code
(too old to reply)
Ashok Chauhan
2003-12-10 05:26:01 UTC
Permalink
****************************
# include <stdio.h>
# include <stdlib.h>
# include <libpq-fe.h>

int main()
{
PGresult *result;
PGconn *conn;
int feild;
printf("successful");
conn = PQconnectdb ("ashok");
result = PQexec (conn, "select * from bill");
feild = PQntuples (result);
printf("%d",feild);
PQclear (result);
PQfinish (conn);
printf("hello");
return 1;


}

I written a code and compile with following command, it complied and
create 'a.out' file but when i run the a.out it give nothing.
command:- "gcc program.c -I /usr/include/pgsql/include -L
/usr/lib/libpq.a -lpq"

plz help me.
Ashok

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ***@postgresql.org
Stephen Powell
2003-12-11 01:57:44 UTC
Permalink
Post by Ashok Chauhan
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;
}
Post by Ashok Chauhan
when i run the a.out it give nothing.
Not even "successful" or "hello" from the printfs?
Post by Ashok Chauhan
plz help me.
Download the programmers manual from here <http://www.postgresql.org/docs/>
--
Stephen Powell


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html
Loading...