The updcd_of sample program from the demo directory
shows how to insert a simple large object from an open file into the
database. The program updates the cat_descr TEXT column of
the catalog table from an open file that contains a series
of records; each consists of a catalog number and the text to update
the corresponding cat_descr column. The program assumes that
this input file has the following format:
\10001\
Dark brown leather first baseman's mitt. Specify right-handed or
left-handed.
\10002\
Babe Ruth signature glove. Black leather. Infield/outfield style.
Specify right- or left-handed.
;
The following figure shows a code excerpt that illustrates
how to use the locator structure to update the cat_descr column
of the catalog table from an open file.
The updcd_of program opens the input file (descfl)
that the user specified in response to a prompt, calls the getcat_num() function
to read a catalog number from the file, and then calls the getdesc_len() function
to determine the length of the text for the update to the cat_descr column.
The program performs a SELECT statement to verify that the catalog
number exists in the catalog table.
If this number exists, the updcd_of program prepares
the locator structure as follows to update cat_descr from the
text in the open file:
The loc_loctype field is set to LOCFILE to tell that
the cat_descr column is to be updated from an open file.
The loc_fd field is set to fd, the file descriptor
for the open-input file.
The loc_oflags field is set to LOC_RONLY, the file-open
mode flag for read-only mode.
The loc_size field is set to length, the length
of the incoming text for cat_descr.
If you insert a null simple-large-object value, your program
also needs to set the loc_indicator field to -1.
The updcd_of program
is then able to perform the database update. After reads
data from the open file and sends it to the database server, updates
the loc_size field with the number of bytes read from the open
file and sent to the database server. also
sets the loc_status field to indicate the status of the operation: 0 for
success and a negative value if an error has occurred. For possible
causes of the error, see Error returns in loc_status.
Have feedback?
Google Analytics is used to store comments and ratings. To provide a comment or rating for a topic, click Accept All Cookies or Allow All in Cookie Preferences in the footer of this page.