README.context_variables 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. After SELECT statements ROW_COUNT always contains zero,
  43. i.e. it can be used for INSERT/UPDATE/DELETE statements only.
  44. It may be a subject of change in the following versions.
  45. 2. ROW_COUNT also contains zero after EXECUTE STATEMENT. That's
  46. a design limitation, because dynamic SQL statements are
  47. executed as nested requests (i.e. in another context).
  48. SQLCODE / GDSCODE (FB 1.5)
  49. --------------------------
  50. Function:
  51. Returns numeric error code for the active exception.
  52. Author:
  53. Dmitry Yemanov <[email protected]>
  54. Syntax rules:
  55. SQLCODE / GDSCODE
  56. Type:
  57. INTEGER
  58. Scope:
  59. PSQL, context of the exception handling block.
  60. Example(s):
  61. BEGIN
  62. ...
  63. WHEN SQLCODE -802 THEN
  64. EXCEPTION E_EXCEPTION_1;
  65. WHEN SQLCODE -803 THEN
  66. EXCEPTION E_EXCEPTION_2;
  67. WHEN ANY DO
  68. EXECUTE PROCEDURE P_ANY_EXCEPTION(SQLCODE);
  69. END
  70. Note(s):
  71. 1. GDSCODE variable returns a numeric representation of the
  72. appropriate Firebird error code.
  73. 2. Both SQLCODE and GDSCODE always evaluate to zero outside
  74. the exception handling block.
  75. 3. If you catch exceptions with 'WHEN SQLCODE' block, then only
  76. SQLCODE variable contains the error code inside this block,
  77. whilst GDSCODE contains zero. Obviously, this situation is
  78. opposite for 'WHEN GDSCODE' block.
  79. 4. For 'WHEN ANY' block, the error code is set in SQLCODE
  80. variable only.
  81. 5. If user-defined exception is thrown, both SQLCODE and GDSCODE
  82. variables contain zero, regardless of the exception handling
  83. block type.
  84. See also:
  85. README.exception_handling
  86. INSERTING / UPDATING / DELETING (FB 1.5)
  87. ----------------------------------------
  88. Function:
  89. Determines type of row operation being executed.
  90. Author:
  91. Dmitry Yemanov <[email protected]>
  92. Syntax rules:
  93. INSERTING / UPDATING / DELETING
  94. Type:
  95. BOOLEAN (emulated via pseudo-expression in FB 1.5)
  96. Scope:
  97. PSQL, triggers only.
  98. Example(s):
  99. IF (INSERTING OR DELETING) THEN
  100. NEW.ID = GEN_ID(G_GENERATOR_1, 1);
  101. See also:
  102. README.universal_triggers