I can't get results inside a C program.

From: "Jay G(dot) Scott" <gl(at)arlut(dot)utexas(dot)edu>
To: pgsql-novice(at)postgresql(dot)org
Subject: I can't get results inside a C program.
Date: 2003-01-29 14:44:59
Message-ID: 3E37E8EB.7040706@arlut.utexas.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

The database has 4 values; I can see them when I get into the d.b.
via:
psql test
and, using (cut and paste) the string the C program uses to select,
from "psql environment" I see the four values. So that's all good.
The string, I suppose, must be okay. Furthermore, if I turn on
tracing, I believe I see the four values being printed. However,
my C program thinks it got 0 rows. And I can't retrieve anything.
here's a code fragment:
/*-----------------------------------------------*/
sprintf(select_stmt, "SELECT m_id FROM machines WHERE hostname = '%s'",
node);
fprintf(stderr,"trying this: %s\n", select_stmt);
/*____________________________________________________________________________*/
igot = PQsendQuery(conn_to_db,select_stmt);
fprintf(stderr,"igot from query is %d\n", igot );
seek_m_id = PQgetResult(conn_to_db);

estgot = PQresultStatus( seek_m_id );

fprintf(stderr,"estgot from PQgetResult is %d\n", estgot );

while( seek_m_id != NULL )
{
fprintf(stderr,"seek_m_id != NULL\n");
seek_m_id = PQgetResult(conn_to_db);
estgot = PQresultStatus( seek_m_id );
tmwh( estgot );
/* i suppose nrows could keep coming back as 1 */
nrows = PQntuples( seek_m_id );
fprintf(stderr,"nrows = %d\n", nrows );
for(jj=0;jj<nrows;jj++)
{
cgot = PQgetvalue( seek_m_id, jj, 0 );
machine_id = atoi( cgot );
fprintf(stderr,"machine_id = %d\n", machine_id );
}
PQclear(seek_m_id);
}
/*____________________________________________________________________________*/
torn#

Browse pgsql-novice by date

  From Date Subject
Next Message Steve_Miller 2003-01-29 15:14:12 Good books?
Previous Message paul butler 2003-01-29 14:05:15 Re: Developing a forms based web application