SQL Programming Manual for TAL

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL527887-001
C-17
Detailed Dynamic SQL Program
Page 6 [1] $VOL1.S04.TALDYN 1991-10-15 13:42:28
display^result
167. 000000 0 0 PROC display^result (sqlda, cnames);
168. 000000 1 0
169. 000000 1 0 !*********************************************************!
170. 000000 1 0 ! PROC display^result !
171. 000000 1 0 ! displays the current row of a SELECT statement !
172. 000000 1 0 !*********************************************************!
173. 000000 1 0
174. 000000 1 0 STRUCT .ext sqlda(sqlda^type); !IN: Output SQLDA
175. 000000 1 0 STRING .ext cnames; !IN: contains column names of table
176. 000000 1 0
177. 000000 1 0 BEGIN
178. 000000 1 1 INT length;
179. 000000 1 1 INT nameix; ! index into column names string
180. 000000 1 1 INT output^num; ! number of columns to be output
181. 000000 1 1 INT i;
182. 000000 1 1 INT .EXT ind^ptr^;
183. 000000 1 1 INT .EXT param^ (sql^types);
184. 000000 1 1 INT datalen; ! length of column value
185. 000000 1 1
186. 000000 1 1 --
187. 000000 1 1 -- Get number of columns to output in current row.
188. 000000 1 1 --
189. 000000 1 1
190. 000000 1 1 output^num := sqlda.num^entries;
191. 000007 1 1
192. 000007 1 1 nameix := 1;
193. 000011 1 1
194. 000011 1 1 FOR i := 0 TO (output^num - 1) DO
195. 000013 1 1 BEGIN
196. 000013 1 2 --
197. 000013 1 2 -- Get a column name (which are stored sequentially in
array;
198. 000013 1 2 -- each column name is preceded in this array by its
length)
199. 000013 1 2 -- and blank pad to 40 characters.
200. 000013 1 2 --
201. 000013 1 2 @next^buf := @sbuf;
202. 000015 1 2 next^buf ':=' MAX^COLUMN^NAME^SIZE * [" "] & " ";
203. 000041 1 2 IF cnames[nameix] = 0 THEN
204. 000050 1 2 next^buf ':=' ["(EXPR)"] -- Use (EXPR) for the
column name if no
205. 000050 1 2 -- column name appears, as SQLCI does.
206. 000050 1 2 ELSE
207. 000063 1 2 next^buf ':=' cnames[nameix+1] FOR cnames[nameix];
208. 000077 1 2 @next^buf := @next^buf[MAX^COLUMN^NAME^SIZE+1];
209. 000104 1 2
210. 000104 1 2 nameix := cnames[nameix] + 2 + nameix;
211. 000115 1 2
212. 000115 1 2 @param^ := sqlda.sqlvar[i].var^ptr;
213. 000130 1 2 @ind^ptr^ := sqlda.sqlvar[i].ind^ptr;
214. 000143 1 2 datalen := sqlda.sqlvar[i].data^len;
215. 000156 1 2
216. 000156 1 2 IF sqlda.sqlvar[i].null^info = -1 AND ind^ptr^ = -1
THEN
217. 000176 1 2 BEGIN
218. 000176 1 3 PUT^STR^MID ("? (NULL)");
219. 000214 1 3 END ELSE BEGIN
220. 000215 1 3 CASE sqlda.sqlvar[i].data^type OF
221. 000230 1 3 BEGIN
222. 000230 1 4 !-------------------------------------------
223. 000230 1 4 ! data type is character; display first 38
characaters