pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: am@fx.ro
To: pgsql-interfaces@postgresql.org
Subject: Handling data in libpq
Date: Sat, 19 Oct 2002 13:23:52 +0300
Message-ID: <20021019132352.A419@coto> (raw)
In-Reply-To: <80bf0666.0210170015.59e12eed@posting.google.com>
References: <80bf0666.0210170015.59e12eed@posting.google.com>

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@fx.ro)
 
                                
     



view thread (5+ messages)  latest in thread

Message-ID: <20021019132352.A419@coto>
Permalink:  ../20021019132352.A419@coto/
Also on:    postgresql.org/message-id/20021019132352.A419@coto

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: am@fx.ro
  Subject: Re: Handling data in libpq
  In-Reply-To: <20021019132352.A419@coto>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox