SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-33
Using Dynamic Cursors
Using Dynamic Cursors
Dynamic SQL statements use cursors to process SELECT statements in the same way
static SQL statements use cursors. The program reads rows from a table, one by one,
and sends the column values to output data buffers specified in the program. The
Figure 7-9. Displaying Output (page 2 of 2)
{ For each column name in the names buffer, move the names }
{ Loop for each column: }
{ to the output file, character by character. Then }
{ display the value for that column. }
{ buffer pointer to point to the name, and write the name }
FOR I := 1 TO NUM_COLUMNS DO
BEGIN
{ Save the length field for the column, from the names }
{ buffer: }
LEN := NAMES_PTR.INT16_FIELD^;
{ Advance the pointer past the length field: }
NAMES_PTR.INT32_FIELD :=
NAMES_PTR.INT32_FIELD + SIZEOF(INT16);
{ Write the column name, character by character: }
FOR J := 1 TO LEN DO
BEGIN
WRITE(NAMESPTR.CHAR_FIELD^);
NAMESPTR.INT32_FIELD :=
NAMESPTR.INT32_FIELD + SIZEOF(CHAR);
{ 1 on NonStop system }
END;
{ Blank fill, print a separator character--code }
{ omitted. Get the data type of the value to be output }
{ Use the DATA_TYPE field in the SQLVAR structure: }
DATA_TYPE := SQLVAR_PTR.SQLVAR_FIELD^.DATA_TYPE;
{ Get the address in VAR_PTR and store it in a }
{ variable for overriding type checking: }
VALUE_PTR.EXTADDR_FIELD :=
SQLVAR_PTR.SQLVAR_FIELD^.VAR_PTR;
...
{ Use an IF statement to check the data type and write }
{ the data at VALUE_PTR depending on the data type. }
{ See Using Data Type Literals for more information. }
{ The WRITE statement is: }
WRITE(VALUE_PTR.CHAR_FIELD^);
END; {DISPLAY_SELECTED_VALUES}
VST0709.vsd