Debian Codegraph @

doc/sql.extensions/README.context_variables

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