BLOB, CLOB, and DBCLOB file reference variables are used for direct file input and output for LOBs, and can be defined in all host languages. Since these are not native data types, SQL extensions are used and the precompilers generate the host language constructs necessary to represent each variable. In the case of REXX, LOBs are mapped to strings.
A file reference variable represents (rather than contains) the file, just as a LOB locator represents, rather than contains, the LOB bytes. Database queries, updates and inserts may use file reference variables to store or to retrieve single column values.
A file reference variable has the following properties:
Within an application, a file should only be referenced in one file reference variable.
As with all other host variables, a file reference variable may have an associated indicator variable.
EXEC SQL BEGIN DECLARE SECTION SQL TYPE IS CLOB_FILE hv_text_file; char hv_patent_title[64]; EXEC SQL END DECLARE SECTION
Following preprocessing this would be:
EXEC SQL BEGIN DECLARE SECTION /* SQL TYPE IS CLOB_FILE hv_text_file; */ struct { unsigned long name_length; // File Name Length unsigned long data_length; // Data Length unsigned long file_options; // File Options char name[255]; // File Name } hv_text_file; char hv_patent_title[64]; EXEC SQL END DECLARE SECTION
Then, the following code can be used to select from a CLOB column in the database into a new file referenced by :hv_text_file.
strcpy(hv_text_file.name, "/u/gainer/papers/sigmod.94"); hv_text_file.name_length = strlen("/u/gainer/papers/sigmod.94"); hv_text_file.file_options = SQL_FILE_CREATE; EXEC SQL SELECT content INTO :hv_text_file from papers WHERE TITLE = 'The Relational Theory behind Juggling';
strcpy(hv_text_file.name, "/u/gainer/patents/chips.13"); hv_text_file.name_length = strlen("/u/gainer/patents/chips.13"); hv_text_file.file_options = SQL_FILE_READ: strcpy(:hv_patent_title, "A Method for Pipelining Chip Consumption"); EXEC SQL INSERT INTO patents( title, text ) VALUES(:hv_patent_title, :hv_text_file);
(25) SQL-FILE-READ in COBOL, sql_file_read in FORTRAN, READ in REXX.
(26) SQL-FILE-CREATE in COBOL, sql_file_create in FORTRAN, CREATE in REXX.
(27) SQL-FILE-OVERWRITE in COBOL, sql_file_overwrite in FORTRAN, OVERWRITE in REXX.
(28) SQL-FILE-APPEND in COBOL, sql_file_append in FORTRAN, APPEND in REXX.