Creates a savepoint in the current transaction. Allows to make a rollback of the transaction until the savepoint created here.
The savepoint can be liberated when necessary. This tag requires which exist previously a transaction or that the connection is not auto-commit in which case a new one will be generated from de moment of the savepoint creation (the created connections from a 'xsql-script' are generally auto-commit, for this reason it is necessary to open a transaction explicitly).
1 connection.savepoint
<connection.savepoint name='name'/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Name of the savepoint. Can be referenced later to make a rollback or simply liberate it. |
Returns | |
---|---|
Type | Description |
Savepoint | Return the created savepoint. |
Exceptions
SQLException
If an error of database access occurs, this methode is called during its participation in a distributed transaction, this methode is called in a closed connection or this connection object is actually in auto-commit mode.
SQLFeatureNotSupportedException
If the JDBC controller is not compatible with this methode.
<xsql-script name='sample_savepoint'> <body> <connection.begin/> <connection.savepoint /> </body> </xsql-script>
<xsql-script name='postgresql_err_transaction'> <body> <!-- ======================================================================== --> <!-- Postgresql generates error when executing the first DML operatio before --> <!-- a block code try-catch with error in body. --> <!-- --> <!-- try --> <!-- body --> <!-- ../.. --> <!-- error-in-body-try --> <!-- end-body --> <!-- catch --> <!-- ../.. --> <!-- end-catch --> <!-- end-try --> <!-- dml-operation XSQLScriptException: org.postgresql.util.PSQLException: --> <!-- ERROR: current transaction is aborted, commands --> <!-- ignored until end of transaction block --> <!-- ======================================================================== --> <println><connection.getEngineTypeName/></println> <!-- true evoid error postgres in the last update after try --> <!-- XSQLScriptException: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block --> <set name='bypass_err_postgres'><false/></set> <update table='ccuentas'> <column name='name'>Instrumental account - 1</column> <where> placon = 'ES' and code = '0000.000.00000' </where> </update> <try> <body> <!-- TRY-BODY-START ; NEED FOR POSTGRES CONTROL ! --> <!-- NOT NEED BUT THAT IS OK ALSO FOR : ids and oracle. --> <if> <expr> <bypass_err_postgres/> </expr> <then> <!-- Evita error: --> <!-- XSQLScriptException: org.postgresql.util.PSQLException: Cannot establish a savepoint in auto-commit mode. --> <if> <expr> <not><connection.isOnTransaction/></not> </expr> <then> <connection.begin/> </then> </if> <connection.savepoint/> </then> </if> <update table='accounts'> <column name='tipcta'>x</column> <where> placon = 'ES' and code = '0000.000.00000' </where> </update> <!-- TRY-BODY-END ; NEED FOR POSTGRES CONTROL ! --> <!-- NOT NEED BUT THAT IS OK ALSO FOR : ids and oracle. --> <if> <expr> <bypass_err_postgres/> </expr> <then> <connection.releaseSavepoint/> </then> </if> </body> <catch> <!-- TRY-CATCH-START ; NEED FOR POSTGRES CONTROL ! --> <!-- NOT NEED BUT THAT IS OK ALSO FOR : ids and oracle. --> <if> <expr> <bypass_err_postgres/> </expr> <then> <connection.rollbackSavepoint/> </then> </if> <set name='m_resp'><error.isSQL/></set> <println>m_resp: [<m_resp/>] <error.message/></println> </catch> </try> <!-- No management of savepoint postgresql produces the error : --> <!-- XSQLScriptException: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block --> <update table='ccuentas'> <column name='name'>Instrumental account - 2</column> <where> placon = 'ES' and code = '0000.000.00000' </where> </update> <println> <vtable> <select> <columns>*</columns> <from table='ccuentas'/> <where> placon = 'ES' and code = '0000.000.00000' </where> </select> </vtable> </println> </body> </xsql-script>