SQL Programming Manual for Pascal

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal528614-001
C-11
Detailed Dynamic SQL Program
60 0 {**********************************************************}
61 0 {* Declare SQLDA. The SQLDA is explicitly declared to provide a
*}
62 0 {* template for dynamic memory allocation for input and output
*}
63 0 {* variables. INCLUDE SQLDA cannot be used here because INCLUDE
*}
64 0 {* SQLDA causes an instance of the type to be declared, and
Pascal *}
65 0 {* bounds checking will not allow a dynamic allocation that is
*}
66 0 {* larger. *}
67 0 {**********************************************************}
68 0 const
69 0 SQLDA_EYE_CATCHER = 'D1';
70 0
71 0 type
72 0 SQLVAR_TYPE = record { a SQL host variable decl }
73 1 data_type : integer;
74 1 ( CASE INTEGER OF
75 1 1: (data_len : INTEGER);
76 1 2: (scale : BYTE;
77 1 nlen : BYTE);
78 1 3: (dt_qualifier : BYTE;
79 1 dt_len : BYTE) );
80 1 ( CASE INTEGER OF
81 1 1: (precision : INTEGER);
82 1 2: (lead_field_precision : BYTE;
83 1 fraction_precision : BYTE) );
84 1 null_info : INTEGER;
85 1 var_ptr : EXTADDR;
86 1 ind_ptr : EXTADDR;
87 1 reserved : INT64;
88 1 END;
89 0
90 0
91 0 SQLDA_HDR = record { fixed part of the SQLDA }
92 1 eye_catcher : fstring(2);
93 1 num_entries : integer;
94 1 end;
95 0
96 0 P_SQLDA_HDR = ^SQLDA_HDR; { ptr to a SQLDA header }
97 0
98 0 {**********************************************************}
99 0 {* Declare some useful data structures. *}
100 0 {**********************************************************}
101 0 type
102 0 { for char/varchar data }
103 0 CHAR_BUF = packed array[1..MAXCHARS] of char;
104 0 P_CHAR_BUF = ^CHAR_BUF;
105 0
106 0 CMND_BUF = string[MAXCMD]; { buffer to store input cmd }
107 0
108 0 HEAP_HDR = record
109 1 nxt : EXTADDR; { ptr to next heap }
110 1 off : longint; { offset to free space }
111 1 end;
112 0 P_HEAP_HDR = ^HEAP_HDR;
113 0
114 0 P_ANY = record { a ubiquitous pointer type }
115 1 case integer of
116 1 0 : (i : longint); { for pointer arithmetic }
117 1 1 : (charp : ^char);
118 1 2 : (cardp : ^cardinal);
119 1 3 : (int16p : ^int16);
120 1 4 : (int32p : ^int32);
121 1 5 : (int64p : ^int64);
122 1 6 : (hvp : ^SQLVAR_TYPE);