Re: help !!!

From: "Goulet, Dick" <DGoulet(at)vicr(dot)com>
To: "apellido jr(dot), wilfredo p(dot)" <apellido(at)mactan(dot)ph>, <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: help !!!
Date: 2004-06-30 14:11:11
Message-ID: 4001DEAF7DF9BD498B58B45051FBEA650146C47A@25exch1.vicorpower.vicr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

PGgetValue returns a character pointer, so if you have:

char *reply_string = NULL;

reply_string = PQgetResult(rex,0,0);

Dick Goulet
Senior Oracle DBA
Oracle Certified 8i DBA

-----Original Message-----
From: apellido jr., wilfredo p. [mailto:apellido(at)mactan(dot)ph]
Sent: Wednesday, June 30, 2004 9:26 AM
To: pgsql-interfaces(at)postgresql(dot)org
Subject: [INTERFACES] help !!!

Hello! im a newbie in C programing as well as Postgresql. The above example
is workin but im having difficulty regarding assigning the result of Query
Select. here's the program

int
main()
{
char UserName[50]; /* holds user
state code */
char query_string[256]; /* holds
constructed SQL query */
PGconn *conn; /* holds
database connection */
PGresult *res; /* holds
query result */

conn = PQconnectdb("dbname=grade"); /* connect
to the database */

if (PQstatus(conn) == CONNECTION_BAD) /* did the
connection fail? */
{
fprintf(stderr, "Connection to database failed.\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
exit(1);
}

printf("Enter Username: "); /* prompt user
for a state code */
scanf("%s", UserName);

sprintf(query_string, /* create an
SQL query string */
"SELECT username, value
FROM table1
where test = 'grade' and username = '%s'", UserName);

res = PQexec(conn, query_string); /* send the
query */

if (PQresultStatus(res) != PGRES_TUPLES_OK) /* did the
query fail? */
{
fprintf(stderr, "SELECT query failed.\n");
PQclear(res);
PQfinish(conn);
exit(1);
}

printf("\n\n\n");
printf("Username : %s\n\n\n", PQgetvalue(res, 0, 0));
printf("Grade : %s \n\n\n", PQgetvalue(res, 0, 1));

PQclear(res); /* free
result */

PQfinish(conn); /*
disconnect from the database */

return 0;
}

############################################################################
########

hello how can i assign to certain variable the output of PQgetvalue(res, 0,
1)? example i want to do like this ...

a = PQgetvalue(res, 0, 1)
printf("Grade : %s \n\n\n", a );

and then after assigning the value of PQgetvalue(res, 0, 1) to a then ...

b = a \ 2;

but it is possible to divide the output of "a" where it is a var and "b" is
integer?

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Nigel J. Andrews 2004-06-30 22:29:32 Re: Released updated Tcl interfaces: pgin.tcl-2.1.0,
Previous Message Bruno Wolff III 2004-06-30 13:54:50 Re: how to execute a function directly