Declare a host variable for a simple large object
Use the loc_t data type to declare host variables
for database values of type TEXT or BYTE. You declare a host variable
for a simple-large-object column with the data type loc_t,
as shown in the following example:
EXEC SQL include locator;
;
EXEC SQL BEGIN DECLARE SECTION;
loc_t text_lob;
loc_t byte_lob;
EXEC SQL END DECLARE SECTION;
A locator variable with a TEXT data type has the loc_type field
of the locator structure set to SQLTEXT. For a BYTE variable, loc_type is
SQLBYTE.
Tip: The sqltypes.h header
file defines both SQLTEXT and SQLBYTE. Therefore, make sure that you
include sqltypes.h before you use these constants.
From the program,
you can both select and insert simple-large-object data into loc_t host
variables. You can also select only portions of a simple-large-object
variable with subscripts on the simple-large-object column name. These
subscripts can be coded into the statement as shown in the following
example:
EXEC SQL declare catcurs cursor for
select catalog_num, cat_descr[1,10]
from catalog
where manu_code = 'HSK';
EXEC SQL open catcurs;
while (1)
{
EXEC SQL fetch catcurs into :cat_num, :cat_descr;
;
}
Subscripts can also be passed as input parameters as the
following code fragment shows:
EXEC SQL prepare slct_id from
'select catalog_num, cat_descr[?,?] from catalog \
where catalog_num = ?'
EXEC SQL execute slct_id into :cat_num, :cat_descr
using :n, :x, :cat_num;