On 17/06/03, Joe Conway (mail@joeconway.com) wrote:
> Rory Campbell-Lange wrote:
> >Is this sensible, efficient, feasible? I have not used cursors before.
> >
> >Or should I simply do 2 separate functions, 1 for NUM_ROWS, the
> >other for the result set I want?
>
> It's hard to offer advice (at least for me) without more context. What
> are you trying to accomplish (in more detail), and in what type of
> application (web, fat client, etc)?
Its a web page <page> of <pages> scenario.
I need to find the total number of rows returned by a specific WHERE,
and turn that into <pages>.
I also need to return a set of rows, using LIMIT and OFFSET to grab a
subset of the rows and return these to the client.
I wondered if I could do this with one call rather than two. My complete
ignorance of how to use cursors is demonstrated in my second imaginary
example! I realise I can do more or less what I want in a single query
by using a LEFT OUTER JOIN to count(n_id) on a duplicate WHERE query.
Just wondered if cursors provide a cleaner looking query to do that.
Thanks!
Rory
Instead of going (psuedocode):
SELECT into record
n_id
FROM
table
WHERE
complex_where;
numrows := NUMROWS;
FOR resulter IN
numrows, this, that, tother
FROM
table
WHERE
complex_where
LIMIT
limit
OFFSET
offset
LOOP
return next resulter;
END LOOP;
I imagine going:
OPEN mycursor FOR
SELECT
this, that, tother
FROM
table
WHERE
complex_where;
numrows := mycursor->NUMROWS (!);
cursor_move(offset);
cursor_get(limit);
somehow get cursor values into a RECORD...
--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>