README.context_variables 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ------------------------
  2. System context variables
  3. ------------------------
  4. CURRENT_CONNECTION / CURRENT_TRANSACTION (FB 1.5)
  5. -------------------------------------------------
  6. Function:
  7. Returns system identifier of the active connection/transaction,
  8. i.e. a connection/transaction, in which context the given SQL
  9. statement is executed.
  10. Author:
  11. Dmitry Yemanov <[email protected]>
  12. Syntax rules:
  13. CURRENT_CONNECTION / CURRENT_TRANSACTION
  14. Type:
  15. INTEGER
  16. Scope:
  17. DSQL, PSQL
  18. Example(s):
  19. 1. SELECT CURRENT_CONNECTION FROM RDB$DATABASE;
  20. 2. NEW.CONN_ID = CURRENT_TRANSACTION;
  21. 3. EXECUTE PROCEDURE P_LOGIN(CURRENT_CONNECTION);
  22. Note(s):
  23. These values are stored on the database header page,
  24. so they will be reset after a database restore.
  25. ROW_COUNT (FB 1.5)
  26. ------------------
  27. Function:
  28. Returns number of rows, affected by the last SQL statement.
  29. Author:
  30. Dmitry Yemanov <[email protected]>
  31. Syntax rules:
  32. ROW_COUNT
  33. Type:
  34. INTEGER
  35. Scope:
  36. PSQL, context of the given procedure/trigger.
  37. Example(s):
  38. UPDATE TABLE1 SET FIELD1 = 0 WHERE ID = :ID;
  39. IF (ROW_COUNT = 0) THEN
  40. INSERT INTO TABLE1 (ID, FIELD1) VALUES (:ID, 0);
  41. Note(s):
  42. 1. It can be used to check whether a SELECT statement returned
  43. any rows or not. Also it can be used to exit a fetch loop
  44. on an explicit PSQL cursor.
  45. 2. ROW_COUNT contains zero after EXECUTE STATEMENT call. That's
  46. a design limitation, because dynamic SQL statements are
  47. executed as nested requests (i.e. in another context).
  48. See also:
  49. README.cursors
  50. SQLCODE / GDSCODE (FB 1.5)
  51. --------------------------
  52. Function:
  53. Returns numeric error code for the active exception.
  54. Author:
  55. Dmitry Yemanov <[email protected]>
  56. Syntax rules:
  57. SQLCODE / GDSCODE
  58. Type:
  59. INTEGER
  60. Scope:
  61. PSQL, context of the exception handling block.
  62. Example(s):
  63. BEGIN
  64. ...
  65. WHEN SQLCODE -802 THEN
  66. EXCEPTION E_EXCEPTION_1;
  67. WHEN SQLCODE -803 THEN
  68. EXCEPTION E_EXCEPTION_2;
  69. WHEN ANY DO
  70. EXECUTE PROCEDURE P_ANY_EXCEPTION(SQLCODE);
  71. END
  72. Note(s):
  73. 1. GDSCODE variable returns a numeric representation of the
  74. appropriate Firebird error code.
  75. 2. Both SQLCODE and GDSCODE always evaluate to zero outside
  76. the exception handling block.
  77. 3. If you catch exceptions with 'WHEN SQLCODE' block, then only
  78. SQLCODE variable contains the error code inside this block,
  79. whilst GDSCODE contains zero. Obviously, this situation is
  80. opposite for 'WHEN GDSCODE' block.
  81. 4. For 'WHEN ANY' block, the error code is set in SQLCODE
  82. variable only.
  83. 5. If user-defined exception is thrown, both SQLCODE and GDSCODE
  84. variables contain zero, regardless of the exception handling
  85. block type.
  86. See also:
  87. README.exception_handling
  88. INSERTING / UPDATING / DELETING (FB 1.5)
  89. ----------------------------------------
  90. Function:
  91. Determines type of row operation being executed.
  92. Author:
  93. Dmitry Yemanov <[email protected]>
  94. Syntax rules:
  95. INSERTING / UPDATING / DELETING
  96. Type:
  97. BOOLEAN (emulated via pseudo-expression in FB 1.5)
  98. Scope:
  99. PSQL, triggers only.
  100. Example(s):
  101. IF (INSERTING OR DELETING) THEN
  102. NEW.ID = GEN_ID(G_GENERATOR_1, 1);
  103. See also:
  104. README.universal_triggers