Handling data in libpq

From: am(at)fx(dot)ro
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Handling data in libpq
Date: 2002-10-19 10:23:52
Message-ID: 20021019132352.A419@coto
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 table is 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(at)fx(dot)ro)


In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jeroen T. Vermeulen 2002-10-19 11:01:36 Re: Handling data in libpq
Previous Message Jeroen T. Vermeulen 2002-10-18 14:23:08 Re: PgDatabase, on heap construction results in SIGSEGV.