docs.intersystems.com
InterSystems IRIS Data Platform 2019.2  /  InterSystems SQL Reference

InterSystems SQL Reference
%INTRANSACTION
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


Shows transaction state.
Synopsis
%INTRANSACTION
%INTRANS
Arguments
None
Description
The %INTRANSACTION statement sets SQLCODE to indicate the transaction state:
%INTRANSACTION returns SQLCODE=0 while a transaction is in progress. This transaction can be an SQL transaction initiated by START TRANSACTION or SAVEPOINT. It can also be an ObjectScript transaction initiated by TSTART.
Transaction nesting has no effect on %INTRANSACTION. SET TRANSACTION has no effect on %INTRANSACTION.
You can also determine transaction state using $TLEVEL. %INTRANSACTION only indicates whether a transaction is in progress. $TLEVEL indicates both whether a transaction is in progress and the current number of transaction levels.
Examples
The following embedded SQL example shows how %INTRANSACTION sets SQLCODE:
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "Before %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(SET TRANSACTION %COMMITMODE EXPLICIT)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "SetTran %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
  &sql(START TRANSACTION)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "StartTran %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(SAVEPOINT a)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "Savepoint %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(ROLLBACK TO SAVEPOINT a)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "Rollback to Savepoint %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(COMMIT)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "After Commit %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL
See Also


Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-08-16 05:50:13