SQL Programming Manual for Pascal

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal528614-001
C-9
Detailed Dynamic SQL Program
The remainder of this appendix shows the program code.
Tandem Pascal (T9256C30 01DEC90)
COPYRIGHT TANDEM COMPUTERS INCORPORATED 1986,1987,1988,1989
1 0 ?list,nomap,xmem
2 0 ?SQL
3 0 ?symbols
4 0
5 0 {**********************************************************}
6 0 {* DSQLPROC : Dynamic SQL PROCessor. *}
7 0 {* This program will accept any SQL DDL or DML statement from
the *}
8 0 {* terminal, prepare the statement, prompt for parameter values,
*}
9 0 {* execute the statement and output the result to the terminal.
*}
10 0 {* Records returned from a SELECT operation will be displayed *}
11 0 {* with column names. *}
12 0 {**********************************************************}
13 0
14 0 program dsqlproc(input,output);
15 0
16 0 {**********************************************************}
17 0 {* D E C L A R A T I O N S *}
18 0 {**********************************************************}
19 0
20 0 {**********************************************************}
21 0 {* Copy in external declarations for SQLCADISPLAY procedure *}
22 0 {* to handle error message display, and SQLDT data type *}
23 0 {* literals. SQLCADISPLAY requires copying in the TYPES *}
24 0 {* definitions. *}
25 0 {**********************************************************}
26 0
27 0 import begin
28 0 ?SOURCE $system.system.PEXTDECS(TYPES, SQLCADISPLAY, SQLDT),
nolist
...
29 0 end;
30 0
31 0 const
32 0 HEAPSIZE = 4096; { allocation per call }
33 0 MAXCHARS = 4096; { max size of a varchar col }
34 0 MAXCMD = 256; { max command string length }
35 0 MAXTRIES = 3; { max # tries to input data }
36 0
37 0 {----The following tokens identify the type of the command. }
38 0 CMD_JUNK_TYP = 0; { an invalid command !! }
39 0 CMD_PREV_TYP = 1; { reuse previous command }
40 0 CMD_SQL_TYP = 2; { is a SQL statement }
41 0 CMD_STOP_TYP = 3; { terminate processing }
42 0
43 0 {----The following command strings must be in uppercase. }
44 0 CMD_PREV_STR = 'REPEAT'; { re-execute the previous }
45 0 { command }
46 0 CMD_PREV_LEN = 6; { length of command string }
47 0 CMD_STOP_STR = 'STOP'; { terminate processing on }
48 0 { this command }
49 0 CMD_STOP_LEN = 4; { length of command string }
50 0
51 0 {----Maximum size for SQL name. }
52 0 SQL_NAME_SIZE = 30;
53 0