Re: migration: parameterized statement and cursor

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Aleksey Onopriyenko <aleksey(dot)alt(at)gmail(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: migration: parameterized statement and cursor
Date: 2010-01-11 21:18:20
Message-ID: 4B4B959C.7060308@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/11/2010 8:16 AM, Aleksey Onopriyenko wrote:
> Hello.
>
> We are trying to migrate from Informix 9.4 to PostgreSQL. As part of
> migration we are porting our client application.
>
> So we need reimplement such functionality:
> 1. Declare a cursor using to _parameterized_ SELECT statement. It should
> be possible to specify cursor's name (and, perhaps, the statement)
> dynamically.
> 2. Open that cursor (in another C-function) passing parameters to it.
> 3. Fetch records from result set.
> 4. Close the cursor.
>
> Steps 2-4 may be repeated if necessary.
>
> Is it possible with ecpg or libpq?
>
> ----
> Best regards,
> Aleksey

You dont need cursors, really.

In code (a little sudo-code), do:

q := prepare('select f1, f2 from table_x where id = $1');

then you can pass it around as you like, until...

q.params[0] := 42;
q.open();

while not q.eof()
begin
print q.field[0].asString, "\n";
q.next();
end

This is NOT libpq sudo-code, its delphi'ish, which uses libpq under the
hood. My point being, you dont really need cursors, just prepare a
select statement, set it params, fire it off, iterate the result set...
done. And its re-useable.

Unless I missed your purpose.

-Andy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Smith 2010-01-11 21:59:11 Re: Huge iowait during checkpoint finish
Previous Message Ivan Sergio Borgonovo 2010-01-11 20:14:02 Re: how much left for restore?