Select a simple large object into memory
The getcd_me sample program from the demo directory shows how to select a simple large object from the database into memory.
The following figure shows a code excerpt that selects
the cat_descr TEXT column of the catalog table into
memory and then displays it.
The program sets the cat_descr locator structure
fields as follows:
- The loc_loctype field is set to LOCMEMORY so that Informix® ESQL/C returns the cat_descr text in a memory buffer.
- The loc_bufsize field is set to
-1
to have Informix® ESQL/C allocate the memory for the buffer. For more information, see A memory buffer that the ESQL/C libraries allocate. - The loc_oflags field is set to
0
because the program does not use a file for the simple large object. - You must always set the loc_mflags field to
0
when you locate a simple large object in memory.
After the SELECT or FETCH statement, the locator structure
contains the following information:
- The loc_buffer field contains the address of the memory buffer.
- The loc_bufsize field contains the size of the loc_buffer buffer. This is the total amount of memory allocated for simple-large-object storage.
- The loc_size field contains the number of bytes of simple-large-object data in loc_buffer.
- The loc_indicator field contains
-1
if the selected simple-large-object value is null. - The loc_status field contains 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.
The program excerpt in Code excerpt from the getcd_me sample program calls prdesc() to display the text that the SELECT statement returned. For a description of the prdesc() function, see Guide to the prdesc.c file. If this program selects a second simple large object, it would need to set the loc_mflags to the LOC_ALLOC constant before the second SELECT statement to prevent memory leaks.
The excerpt also displays the cat_descr column
for a catalog number that the user enters. The following figure shows
the user input and the output from the cat_descr column of
the stores7 demonstration database.