SQL Programming Manual for TAL
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL—527887-001
C-5
Dynamic SQL Program
Page 3 [5] $SYSTEM.#3191 1991-10-15
13:41:54
19. 002336 0 2 ! fraction precision = precision.<8:15>
20. 002336 0 2 INT null^info;
21. 002336 0 2 INT(32) var^ptr;
22. 002336 0 2 INT(32) ind^ptr;
23. 002336 0 2 FIXED reserved;
24. 002336 0 2 END;
25. 002336 0 1 END;
Source file: [1] $VOL1.S04.TALDYNEZ 1991-10-15 13:36:01
52. 002336 0 0 STRUCT .OSQLDA(osqlda^type);
53. 002354 0 0
54. 002354 0 0 EXEC SQL END DECLARE SECTION;
55. 002354 0 0
56. 002354 0 0 -- Copy declarations from EXTDECS file for:
57. 002354 0 0 --
MYTERM,INITIALIZER,SQLCADISPLAY,OPEN,WRITE,WRITEREAD,STOP,DNUMOUT
58. 002354 0 0
59. 002354 0 0 ?NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS (
63. 000000 0 0
64. 000000 0 0 -- Declare WHENEVER clause for error checking:
65. 000000 0 0 PROC ERROR^HANDLER; FORWARD;
66. 000000 0 0 EXEC SQL WHENEVER SQLERROR CALL :ERROR^HANDLER;
67. 000000 0 0
68. 000000 0 0
69. 000000 0 0 !--------------------------------------------------------
70. 000000 0 0 ! PROC PROCESS^AND^EXECUTE;
71. 000000 0 0 !
72. 000000 0 0 ! Prepares the command; issues DESCRIBE to get description of
73. 000000 0 0 ! the output variable; sets VAR^PTR to point to the memory for
74. 000000 0 0 ! the output variable (average salary); sets up and uses a
75. 000000 0 0 ! cursor to perform the SELECT and output the average.
76. 000000 0 0 !--------------------------------------------------------
77. 000000 0 0
78. 000000 0 0 PROC PROCESS^AND^EXECUTE (CMD);
79. 000000 1 0
80. 000000 1 0 STRING .CMD;
81. 000000 1 0
82. 000000 1 0 BEGIN
83. 000000 1 1 EXEC SQL BEGIN DECLARE SECTION;
84. 000000 1 1
85. 000000 1 1 -- Create an alternate version of CMD that is an array.
86. 000000 1 1 -- We must do this because you cannot put bounds on a
parameter.
87. 000000 1 1 -- In order to pass CMD as a string, we must create this
88. 000000 1 1 -- equivalence. To use CMD as a host variable, we then
reference
89. 000000 1 1 -- CMDX.VAL
90. 000000 1 1
91. 000000 1 1 STRUCT S(*);
92. 000000 1 1 BEGIN
93. 000000 1 2 STRING VAL [0:MAXCMD - 1];
94. 000000 1 2 END;
95. 000000 1 1
96. 000000 1 1 STRING .CMDX(S) = CMD;
97. 000000 1 1
98. 000000 1 1 EXEC SQL END DECLARE SECTION;
99. 000000 1 1
100. 000000 1 1 EXEC SQL PREPARE DYNCMD FROM :CMDX.VAL;
101. 000050 1 1
102. 000050 1 1 OSQLDA.EYE^CATCHER ':=' SQLDA^EYE^CATCHER;
103. 000061 1 1