README.PSQL_stack_trace.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. PSQL stack trace
  2. Function:
  3. Send to client within status-vector simple stack trace with names of stored procedures
  4. and/or triggers. Status-vector appends with following items :
  5. isc_stack_trace, isc_arg_string, <string length>, <string>
  6. isc_stack_trace is a new error code with value of 335544842L
  7. Stack trace is represented by one string and consists from all the sp/trigger names
  8. starting from point where exception occurred up to most outer caller. Maximum length of
  9. that string is 2048 bytes. If actual trace is longer then it will be truncated to this limit.
  10. Author:
  11. Vlad Horsun <horsun at kdb.dp.ua>
  12. Examples:
  13. 0. Create metadata:
  14. CREATE TABLE ERR (ID INT NOT NULL PRIMARY KEY, NAME VARCHAR(16));
  15. CREATE EXCEPTION EX '!';
  16. CREATE OR ALTER PROCEDURE ERR_1 AS
  17. BEGIN
  18. EXCEPTION EX 'ID = 3';
  19. END;
  20. CREATE OR ALTER TRIGGER ERR_BI FOR ERR BEFORE INSERT AS
  21. BEGIN
  22. IF (NEW.ID = 2)
  23. THEN EXCEPTION EX 'ID = 2';
  24. IF (NEW.ID = 3)
  25. THEN EXECUTE PROCEDURE ERR_1;
  26. IF (NEW.ID = 4)
  27. THEN NEW.ID = 1 / 0;
  28. END;
  29. CREATE OR ALTER PROCEDURE ERR_2 AS
  30. BEGIN
  31. INSERT INTO ERR VALUES (3, '333');
  32. END;
  33. 1. User exception from trigger:
  34. SQL> INSERT INTO ERR VALUES (2, '2');
  35. Statement failed, SQLCODE = -836
  36. exception 3
  37. -ID = 2
  38. -At trigger 'ERR_BI'
  39. 2. User exception from procedure called by trigger:
  40. SQL> INSERT INTO ERR VALUES (3, '3');
  41. Statement failed, SQLCODE = -836
  42. exception 3
  43. -ID = 3
  44. -At procedure 'ERR_1'
  45. At trigger 'ERR_BI'
  46. 3. Division by zero occurred in trigger:
  47. SQL> INSERT INTO ERR VALUES (4, '4');
  48. Statement failed, SQLCODE = -802
  49. arithmetic exception, numeric overflow, or string truncation
  50. -At trigger 'ERR_BI'
  51. 4. User exception from procedure:
  52. SQL> EXECUTE PROCEDURE ERR_1;
  53. Statement failed, SQLCODE = -836
  54. exception 3
  55. -ID = 3
  56. -At procedure 'ERR_1'
  57. 5. User exception from procedure with more deep call stack:
  58. SQL> EXECUTE PROCEDURE ERR_2;
  59. Statement failed, SQLCODE = -836
  60. exception 3
  61. -ID = 3
  62. -At procedure 'ERR_1'
  63. At trigger 'ERR_BI'
  64. At procedure 'ERR_2'