Returns TRUE if it is a database error not controlled by the program, as can be a constraint, lack of space in the dbspace... A "Raise Exception (746)" is a controlled error and in this case, the function will return FALSE.
In the massive transactional processes, where individual transactions by document are performed, it will allow to force the unconditional stop of the process and show the SQL error message. It is generally used at he end of a catch block.
1 error.isSQL
<error.isSQL />
Returns | |
---|---|
Type | Description |
Boolean | Returns TRUE if the error is considered of SQL, FALSE in the opposite case. |
Example
Copy
<xsql-script name='sample_error_isSQL'> <body> <try> <body> <!-- In this case, a controlled error of overlapping dates occurs. --> <update table='ctipoimp'> <column name='fecini'><date.mdy m='7' d='1' y='2010' /></column> <where>codimp = 'NOR' and fecfin = <mdy m='12' d='31' y='3000' /></where> </update> </body> <catch> <println>is SQL error? <error.isSQL/></println> </catch> </try> </body> </xsql-script>
Returns:
Copy
is SQL error? false
Example
Code for test in several database managers.
Copy
<xsql-script name='test_issql'> <body> <!-- ============================================================= --> <!-- Test error.isSQL = --> <!-- true : Any constraint error. --> <!-- true : Any database error, ie: *while cursor open* --> <!-- false : User XSQL exception. --> <!-- false : Trigger custom exception with : sdm_raise_msg --> <!-- --> <!-- Determine if the error has been produced by a SQL operation --> <!-- SQL. --> <!-- --> <!-- n the massive transactional processes, where individual --> <!-- transactions by document are performed, it will allow --> <!-- to force the unconditional stop of the process and show --> <!-- the SQL error message. --> <!-- --> <!-- It is used generally at the end of a catch block. --> <!-- --> <!-- ============================================================= --> <!-- ==================================================== --> <!-- Error user exception from XSQL Script. --> <!-- The error must be false. --> <!-- ==================================================== --> <try> <body> <exception>XSQL exception error</exception> </body> <catch> <set name='m_resp'><error.isSQL/></set> <println>XSQL exception error must be false: [<m_resp/>] error.message: [<error.message/>]</println> </catch> </try> <!-- ==================================================== --> <!-- Error Check constraint. --> <!-- Other errors : --> <!-- Not enough space in chunk --> <!-- *while cursor open* --> <!-- The error must be true. --> <!-- ==================================================== --> <try> <body> <!-- ==================================================== --> <!-- TRY-BODY-START --> <!-- Need for postgresql : --> <!-- ==================================================== --> <if> <expr> <not><connection.isOnTransaction/></not> </expr> <then> <connection.begin/> </then> </if> <connection.savepoint/> <!-- Force error : 530: Check constraint (informix.c_ccuentas1) failed. --> <update table='ccuentas'> <column name='tipcta'>x</column> <where> placon = 'ES' and (codigo IN ('0000.000.00000', '0000.00000')) </where> </update> <!-- ==================================================== --> <!-- TRY-BODY-END --> <!-- Need for postgresql : --> <!-- ==================================================== --> <connection.releaseSavepoint/> </body> <catch> <!-- ==================================================== --> <!-- TRY-CATCH-START --> <!-- Need for postgresql : --> <!-- ==================================================== --> <connection.rollbackSavepoint/> <set name='m_resp'><error.isSQL/></set> <println>SQL error must be true: [<m_resp/>] error.message: [<error.message/>]</println> </catch> </try> <!-- ==================================================== --> <!-- Error user exception from trigger ! --> <!-- The error must be false. --> <!-- ==================================================== --> <set name='m_fecfin' type='date'>31-12-3000</set> <set name='m_fecfin_new' type='date'>01-06-2010</set> <try> <body> <update table='ctipoimp'> <column name='fecini'><m_fecfin_new/></column> <where> codimp = 'NOR' and fecfin = <m_fecfin/> </where> </update> </body> <catch> <set name='m_resp'><error.isSQL/></set> <println>Trigger exception error must be false: [<m_resp/>] error.message: [<error.message/>]</println> <println>error.sqlstate: [<error.sqlstate/>] error.sqlcode: [<error.sqlcode/>] </println> </catch> </try> </body> </xsql-script>