Re: V8.3.0: PQprepare()/PQexecPrepared() and DECLARE CURSOR
От | Sebastien FLAESCH |
---|---|
Тема | Re: V8.3.0: PQprepare()/PQexecPrepared() and DECLARE CURSOR |
Дата | |
Msg-id | 4767E217.7010902@4js.com обсуждение исходный текст |
Ответ на | Re: V8.3.0: PQprepare()/PQexecPrepared() and DECLARE CURSOR (Andrew Dunstan <andrew@dunslane.net>) |
Ответы |
Re: V8.3.0: PQprepare()/PQexecPrepared() and DECLARE CURSOR
|
Список | 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 >
В списке pgsql-hackers по дате отправления: