I am trying to make SQLScript procedure with a nice way of exception handling. The idea is to catch:
1) System exceptions
2) Logical exceptions
and send info to the output.
For the moment i have:
CREATE PROCEDURE<schema>.TEST01 (OUTes_errorNVARCHAR(50))
LANGUAGESQLSCRIPT
SQLSECURITYINVOKERAS
BEGIN
DECLAREMYCONDCONDITIONFORSQL_ERROR_CODE 10001;
DECLAREEXITHANDLERFORSQLEXCEPTION
BEGIN
es_error := 'err';
END;
<if logical error>
SIGNALMYCOND;
</if logical error>
<test of SQL error>
INSERTINTO<schema>."TMP_TEST01"VALUES(1);
INSERTINTO<schema>."TMP_TEST01"VALUES(1);
</test of SQL error>
es_error := 'ok';
END;
The problem is in the fact, that i can catch errors, but i can't distinguish between them.
Of course before "SIGNAL MYCOND" i can put text of error in variable and send it to the output, but the main problem i can't get code of SQL exception. How can it be done?
In SQL Script documentation there is something like :
DECLARE EXIT HANDLER FOR MYCOND SELECT ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE FROM DUMMY;
But complier can't find corresponding columns in DUMMY...
So, does anybody know how SQL exception code can be caught?
PS: SP05 rev 52.