Handling data in libpq - Mailing list pgsql-interfaces

From am@fx.ro
Subject Handling data in libpq
Date
Msg-id 20021019132352.A419@coto
Whole thread Raw
In response to ANN: EMS PostgreSQL Utils released!  (dkovt@ems-hitech.com (Danya Kovtunowitch))
Responses Re: Handling data in libpq
List pgsql-interfaces
Hello everyone!

I have written a C program that:
- displays in a tabular form the data in a table
- allows inserts,deletes,updates, and user-defined filters('enter a query')
- uses libpq and ncurses.

The program is rather inefficient right now : 
- In order to fetch the data, i call:      RecordSet = PQexec(conn,"select FIELD1,...,FIELDn,OID from TBL");
nRecords = PQntuples(RecordSet);
 

- when i need a specific tuple, i call :    PQgetvalue(RecordSet,crtRecord,field);   for each field


I'm looking for a new approach regarding fetching the data.
Usage of cursors is probably the path to follow. I would be deeply 
grateful to anyone who would share a bit of his/her experience:

- i assume the table has 50000 tuples
- what is better:  to fetch one tuple at one time, or to fetch a certain number of tuples (let's say 100).
- if i fetch 100 tuples, PQntuples returns 100? how do i know how many rows has the table?  
- i have the impression that keeping track of the tuple's index i nside the RecordSet and the index inside the whole
tableis quite  tricky, but manageable. How do you guys handle this kind of situations?
 
- are there more examples that use cursors, except the ones in docs ( in the libpq chapter )?    
Thanks,
Adrian Maier
(am@fx.ro)                                   


pgsql-interfaces by date:

Previous
From: "Jeroen T. Vermeulen"
Date:
Subject: Re: PgDatabase, on heap construction results in SIGSEGV.
Next
From: "Jeroen T. Vermeulen"
Date:
Subject: Re: Handling data in libpq