Savepoints and SPI

Started by Thomas Hallgrenalmost 21 years ago3 messages
#1Thomas Hallgren
thhal@mailblocks.com

I have some test code that utilize SPI and does the following:

1. SPI_connect
2. set a savepoint (using BeginInternalSubTransaction)
3. execute a statement that contains a syntax error (within PG_TRY/PG_CATCH)
4. rollback to the savepoint (RollbackAndReleaseCurrentSubTransaction)
5. execute some other statement.

it errors out in step 5 with SPI_ERROR_UNCONNECTED. It seems that step
3, when it encounters an error, automatically executes a SPI_finish. Is
that the desired behavior?

Should I assume that _all_ errors will act this way, i.e. should I
assume that if I end up in a PG_CATCH() that my SPI has been
disconnected always?

Regards,
Thomas Hallgren

#2Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: Thomas Hallgren (#1)
Re: Savepoints and SPI

On Wed, Mar 16, 2005 at 07:35:57PM +0100, Thomas Hallgren wrote:

I have some test code that utilize SPI and does the following:

1. SPI_connect
2. set a savepoint (using BeginInternalSubTransaction)
3. execute a statement that contains a syntax error (within PG_TRY/PG_CATCH)
4. rollback to the savepoint (RollbackAndReleaseCurrentSubTransaction)
5. execute some other statement.

it errors out in step 5 with SPI_ERROR_UNCONNECTED. It seems that step
3, when it encounters an error, automatically executes a SPI_finish. Is
that the desired behavior?

I'd expect the code to close an SPI connection that is opened inside the
savepoint, but if you open it before setting the savepoint then it
should remain open.

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"Endurecerse, pero jam�s perder la ternura" (E. Guevara)

#3Thomas Hallgren
thhal@mailblocks.com
In reply to: Alvaro Herrera (#2)
Re: Savepoints and SPI

Alvaro Herrera wrote:

On Wed, Mar 16, 2005 at 07:35:57PM +0100, Thomas Hallgren wrote:

I have some test code that utilize SPI and does the following:

1. SPI_connect
2. set a savepoint (using BeginInternalSubTransaction)
3. execute a statement that contains a syntax error (within PG_TRY/PG_CATCH)
4. rollback to the savepoint (RollbackAndReleaseCurrentSubTransaction)
5. execute some other statement.

it errors out in step 5 with SPI_ERROR_UNCONNECTED. It seems that step
3, when it encounters an error, automatically executes a SPI_finish. Is
that the desired behavior?

I'd expect the code to close an SPI connection that is opened inside the
savepoint, but if you open it before setting the savepoint then it
should remain open.

That doesn't seem to be what happens. ISTM that the AtEOSubXact_SPI will
do this always:

_SPI_connected--;
_SPI_curid = _SPI_connected;

which in essence puts SPI in an unconnected state regardless of what the
values where before on the _SPI_connected and _SPI_curid.

Regards,
Thomas Hallgren