Re: Functions like: GetNextRecord . .

From: Doug McNaught <doug(at)wireboard(dot)com>
To: pri(at)chu(dot)com(dot)au
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Functions like: GetNextRecord . .
Date: 2001-12-12 11:58:12
Message-ID: m3lmg8wsyz.fsf@belphigor.mcnaught.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Philip Rhoades <pri(at)chu(dot)com(dot)au> writes:

> Hi all,
>
> We are changing our CodeBase (DBF) tables to Postgres but we have to
> keep our character based, C apps for the time being. To reduce the
> amount of code conversion we need to have functions like:
>
> GetRecord
> GetNextRecord
> GetPrevRecord
> GetTopRecord
> GetBottomRecord
>
> - the information for the record is in a C struct and this is
> passed to the appropriate function.
>
> Just about all the apps need this sort of thing to be able to iterate
> through the records from a particular point in the table - is there
> some way of doing this with PG?

Sure, though it's probably not totally straightforward. After opening
a connection, do something like

result = PQexec(conn, "select * from mytable");

if (PQresultStatus(conn, result) == PGRES_TUPLES_OK) {
nrows = PQntuples(result);
}

Your various Get*Record routines would then use PQgetvalue() to fetch
the appropriate fields from the right tuple and format them into the
record your caller is expecting.

See the libpq docs:

http://www.au.postgresql.org/users-lounge/docs/7.1/programmer/libpq.html

If multiple users will be hitting (and changing) the database at the
same time, you need to think about what that means, as PG will likely
not give you the same behavior as DBF files. See the doc sections on
"Multi-version concurrency control".

Hope this helps...

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Holger Krug 2001-12-12 13:56:39 Re: ODBC to Windows
Previous Message Raymond O'Donnell 2001-12-12 11:43:15 Re: Can't pg_dump