Philip Rhoades <pri@chu.com.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