File: README.leave_labels

package info (click to toggle)
firebird3.0 3.0.13.ds7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,632 kB
  • sloc: ansic: 374,403; cpp: 319,973; sql: 14,691; pascal: 14,532; yacc: 7,557; fortran: 5,645; sh: 5,336; makefile: 1,041; perl: 194; sed: 83; awk: 76; xml: 19; csh: 15
file content (64 lines) | stat: -rw-r--r-- 1,723 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
----------------------------------------
PSQL labels and LEAVE statement (FB 2.0)
----------------------------------------

  Function:
    Allows to stop execution of the current block and unwind to the specified label.
    After that execution continues from the statement following by the terminated loop statement.

  Author:
    Dmitry Yemanov <dimitr@users.sf.net>

  Syntax rules:
    <label_name>: <loop_statement>
    ...
    LEAVE [<label_name>]
    
    Where <loop_statement> is one of: WHILE, FOR SELECT, FOR EXECUTE STATEMENT

  Example(s):
    1. FOR
         SELECT COALESCE(RDB$SYSTEM_FLAG, 0), RDB$RELATION_NAME
         FROM RDB$RELATIONS
         ORDER BY 1
         INTO :RTYPE, :RNAME
       DO
       BEGIN
         IF (RTYPE = 0) THEN
           SUSPEND;
         ELSE
           LEAVE; -- exits current loop
       END

    2. CNT = 100;
       L1:
       WHILE (CNT >= 0) DO
       BEGIN
         IF (CNT < 50) THEN
           LEAVE L1; -- exists WHILE loop
         CNT = CNT - l;
       END

    3. STMT1 = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS';
       L1:
       FOR
         EXECUTE STATEMENT :STMT1 INTO :RNAME
       DO
       BEGIN
         STMT2 = 'SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME = ';
         L2:
         FOR
           EXECUTE STATEMENT :STMT2 || :RNAME INTO :FNAME
         DO
         BEGIN
           IF (RNAME = 'RDB$DATABASE') THEN
             LEAVE L1; -- exits the outer loop
           ELSE IF (RNAME = 'RDB$RELATIONS') THEN
             LEAVE L2; -- exits the inner loop
           ELSE
             SUSPEND;
         END
       END

  Note(s):
    LEAVE without explicit lable means interrupting the current (most inner) loop.