Subject Re: [IBO] How to detect a read only transaction in SP?
Author Daniel Rail
Hi,

At April 24, 2005, 06:26, Bjoern Reimer wrote:


> I'm to sure wether this is a firebird or a IBO question. But I
> think Helen know the answer and shes on both lists :-)

> I'm using the read only property of TIB_transaction.

> The help file says only:

> "Makes this transaction ReadOnly at the API level."

> My Question: How can I detect in an SP (or Trigger) that the
> transaction is ReadOnly? I only have the current_transaction
> in FB 1.5 but I can't find a way to see whether its a
> ReadOnly transaction or not.

> My idea is to have a code snippet in the log sub sp like

> if (current_transaction IS NOT readonly) then
> <Insert into Log-Table>

You could try it this way:

BEGIN
<Insert into Log-Table>
WHEN SQLCODE -817 DO
B=1; /* B is just a dummy variable */
END

SQLCODE -817 represents the that you are attempting an update/insert
on a read-only transaction.

Also, as a note, the WHEN <error> DO should be placed at the end of a
BEGIN...END block of code and preferably after a SUSPEND, if one
exists. So if your insert statement is in the middle of your stored
procedure, simply enclose it within a BEGIN...END with the WHEN
<error> DO statement.

You can find more error codes in the IB6 beta Language Reference
document, or in Helen's book "The Firebird Book". Also, in either
references, you'll find documentation on the WHEN <error> DO
statement.

--
Best regards,
Daniel Rail
Senior System Engineer
ACCRA Group Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)