SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-15
Dynamically Allocating Memory
Using A Record Variant. The type PTR_TO_ANY in the following example allows you
to create pointers to any of the data types in the CASE statement:
PTR_TO_ANY = record
case integer of
1 : (char_field : ^char);
2 : (cardinal_field : ^cardinal);
3 : (int16_field : ^int16);
4 : (int32_field : ^int32);
5 : (int64_field : ^int64);
6 : (sqlvar_field : ^ sqlvar structure in sqlda);
7 : (sqlda_header_field : ^ sqlda header fields);
8 : (buffer_field : ^ statement buffer );
9 : (extaddr_field : ^ extaddr item
( special Tandem data type );
... others as needed
end;
You can now declare variables of type PTR_TO_ANY that are type compatible with
one another. For example, you can assign a function result stored in a character
variable to an integer variable, because both variables are of type PTR_TO_ANY.
The sample code in this section assumes that this technique is used and designates
variables as variable_name.int32_field, variable_name.char_field, and
so forth.
Using RETYPE. You can also use the RETYPE function to convert a value to another
data type. RETYPE makes it explicit that you are doing type conversion.
Examples 1 and 2 assume that you have the following pointer declarations for an
SQLVAR array and header in an input or output SQLDA:
TYPE
SQLDA_HEADER_TYPE = RECORD
EYE_CATCHER : FSTRING(2);
NUM_ENTRIES : INTEGER;
END;
SQLDA_HEADER_PTR_TYPE = ^SQLDA_HEADER_TYPE;
SQLVAR_TYPE = RECORD { simplified for this example }
DATA_TYPE : INTEGER;
DATA_LEN : INTEGER;
NULL_INFO : INTEGER;
VAR_PTR : EXTADDR;
IND_PTR : EXTADDR;
END;
SQLVAR_PTR_TYPE = ^SQLVAR_TYPE;
VAR
SQLDA_HEADER_PTR : SQLDA_HEADER_PTR_TYPE;
SQLVAR_PTR : SQLVAR_PTR_TYPE;
T : INT32;
SIZE_TO_ALLOCATE : LONGINT;