Re: V8.3.0: PQprepare()/PQexecPrepared() and DECLARE CURSOR

From: Sebastien FLAESCH <sf(at)4js(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: V8.3.0: PQprepare()/PQexecPrepared() and DECLARE CURSOR
Date: 2007-12-18 15:07:03
Message-ID: 4767E217.7010902@4js.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you Andrew,

I agree the example is a bit confusing, anyway it's my fault... problem fixed.

However, could you please confirm that I can use the same name for a prepared statement and a server cursor?

This seems to work:

test1=> declare s1 cursor with hold for select * from dbit2;
test1=> open s1;
test1=> prepare s1 as select * from dbit2; -- or PQprepare ( "s1" )
test1=> execute s1;

As these are different objects for PostgreSQL - right?

Seb

Andrew Dunstan wrote:
> Sebastien FLAESCH wrote:
>> For SQL producing a result set:
>>
>> PQprepare(... "cu1", "DECLARE cu1 CURSOR WITH HOLD ..." );
>> PQexecPrepared( ... "cu1" ... ); -- opens the cursor...
>> PQexec( "FETCH NEXT FROM cu1 ..." ... );
>> PQexec( "FETCH NEXT FROM cu1 ..." ... );
>> PQexec( "FETCH NEXT FROM cu1 ..." ... );
>> PQexec( "CLOSE cu1" ); -- frees cursor resources (need to re-execute
>> DECLARE)
>> PQexecPrepared( ... "cu1" ... ); -- opens the cursor...
>> PQexec( "FETCH NEXT FROM cu1 ..." ... );
>> PQexec( "FETCH NEXT FROM cu1 ..." ... );
>> PQexec( "CLOSE cu1" ); -- frees cursor resources (need to re-execute
>> DECLARE)
>> PQexecPrepared( ... "cu1" ... ); -- Here I get error:
>> [42P03][cursor "cu1" already exists]
>>
>> I wonder why the second PQexecPrepare() executes and the third fails...
>>
>> To make this work, I need to de-allocate the statement and re-prepare
>> with PQprepare() ...
>>
>> I will try to provide you with a little sample to reproduce, but
>> wanted to post this early to let you known.
>>
>
> This example would be clearer if you used different names for the cursor
> and the prepared statement.
>
> cheers
>
> andrew
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2007-12-18 15:07:37 Re: pgsql: Improve wording.
Previous Message Michał Zaborowski 2007-12-18 15:01:52 Re: VLDB Features