Insert a simple large object from memory
The updcd_me sample program from the demo directory shows how to insert a simple large object from memory into the database.
The program updates the cat_descr TEXT column of
the catalog table from a memory buffer that contains text that
the user enters. The following figure shows sample output as the user
updates the cat_descr column of the stores7 database.
The following figure shows a code excerpt that illustrates
how the updcd_me program uses the locator structure to update
the cat_descr column from the text that is stored in memory.
The program sets the cat_descr locator structure
fields as follows:
- The loc_loctype field is set to LOCMEMORY so that Informix® ESQL/C reads the cat_descr text from a memory buffer.
- The loc_buffer field is set to ans, the address of the memory buffer that holds the simple-large-object value to be inserted.
- The loc_bufsize field is set to BUFFSZ, the size of the allocated ans memory buffer.
- The loc_size field is set to strlen(ans) +
1
, the number of bytes in the memory buffer that currently holds the new simple-large-object value.
If you insert a null simple-large-object value, your program
also needs to set the loc_indicator field to -1
.
The
following figure shows a code excerpt that illustrates how to use
a locator structure in an INSERT statement.
After the UPDATE or INSERT statement, Informix®
ESQL/C updates
the loc_size field with the number of bytes read from the memory
buffer and sent to the database server. It 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 information about
possible errors, see Allocate the memory buffer.