2. Open the smart large object with the ifx_lo_open() function.
3. Perform the appropriate read or write operations to update the data of the smart large object.
4. Close the smart large object with the ifx_lo_close() function.
Figure 7-5 shows how the database server transfers the data of a smart large object to the ESQL/C client application.
Figure 7-5 Transferring Smart- Large-Object Data from Database Server to Client Application
For a sample of code that selects a smart large object from a database column, see "The create_clob Program". For information on how to store a smart large object in the database, see page 7-17.
Opening a Smart Large Object When you open a smart large object, you obtain an LO file descriptor for the smart large object. Through the LO file descriptor you can access the data of a smart large object as if it were in an operating-system file. Access Modes When you open a smart large object, you specify the access mode for the data. The access mode determines which read and write operations are valid on the open smart large object. You specify an access mode with one of the access-mode constants that the locator.h file defines. Figure 7-6 shows the access modes and their corresponding defined constants that the ifx_lo_open() and ifx_lo_create() functions support.
Figure 7-6 Access-Mode Flags for Smart Large Objects Access Mode Purpose Access-Mode Constant Read-only mode Only read operations are valid on the data. LO_RDONLY Write-only mode Only write operations are valid on the data. LO_WRONLY Write/append mode Appends any data you write to the end of the smart large object. By itself, it is equivalent to write-only mode followed by a seek to the end of the smart large object. Read operations fail. LO_APPEND Read/write mode Both read and write operations are valid on the data. LO_RDWR Buffered access Use standard database server buffer pool. LO_BUFFER Lightweight I/O Use private buffers from the session pool of the database server. LO_NOBUFFER
Read-only mode
Only read operations are valid on the data.
LO_RDONLY
Write-only mode
Only write operations are valid on the data.
LO_WRONLY
Write/append mode
Appends any data you write to the end of the smart large object. By itself, it is equivalent to write-only mode followed by a seek to the end of the smart large object. Read operations fail.
LO_APPEND
Read/write mode
Both read and write operations are valid on the data.
LO_RDWR
Buffered access
Use standard database server buffer pool.
LO_BUFFER
Lightweight I/O
Use private buffers from the session pool of the database server.
LO_NOBUFFER
LO_RDONLY | LO_APPEND
Occur at the file position and then move the file position to the end of the data that has been read
Fail and do not move the file position.
LO_WRONLY | LO_APPEND
Fail and do not move the file position
Move the file position to the end of the smart large object and then write the data; file position is at the end of the data after the write.
LO_RDWR | LO_APPEND
Lightweight I/O When the database server accesses smart large objects, it uses buffers from the buffer pool for buffered access. Unbuffered access is called lightweight I/O. Lightweight I/O uses private buffers instead of the buffer pool to hold smart large objects. These private buffers are allocated out of the database server session pool. Lightweight I/O allows you to bypass the overhead of the least-recently-used (LRU) queues that the database server uses to manage the buffer pool. For more information about LRUs, see the INFORMIX-Universal Server Performance Guide. You can specify lightweight I/O by setting the flags parameter to LO_NOBUFFER when you create a smart large object with the ifx_lo_create() function or when you open a particular smart large object with the ifx_lo_open() function. To specify buffered access, which is the default, use the LO_BUFFER flag.
2. Store the LO-pointer for the smart large object in the database with the UPDATE or INSERT statement.
Reading Data From a Smart Large Object The ifx_lo_read() and ifx_lo_readwithseek() ESQL/C library functions read data from an open smart large object. They both read a specified number of bytes from the open smart large object into the user-defined character buffer. The ifx_lo_read() function begins the read operation at the current file position. You can specify the starting file position of the read with the ifx_lo_seek() function, and you can obtain the current file position with the ifx_lo_tell() function. The ifx_lo_readwithseek() function performs the seek and read operations with a single function call. The ifx_lo_read() and ifx_lo_readwithseek() functions require a valid LO file descriptor to identify the smart large object to be read. You obtain an LO file descriptor with the ifx_lo_open() or ifx_lo_create() function. For more information, see the descriptions of the ifx_lo_read() function on page 7-55 and the ifx_lo_readwithseek() function on page 7-57.
Writing Data to a Smart Large Object The ifx_lo_write() and ifx_lo_writewithseek() ESQL/C library functions write data to an open smart large object. They both write a specified number of bytes from a user-defined character buffer to the open smart large object. The ifx_lo_write() function begins the write operation at the current file position. You can specify the starting file position of the write with the ifx_lo_seek() function, and you can obtain the current file position with the ifx_lo_tell() function. The ifx_lo_writewithseek() function performs the seek and write operations with a single function call. The ifx_lo_write() and ifx_lo_writewithseek() functions require a valid LO file descriptor to identify the smart large object to write. You obtain an LO file descriptor with the ifx_lo_open() or ifx_lo_create() function. For more information, see the descriptions of the ifx_lo_write() function on page 7-96 and the ifx_lo_writewithseek() function on page 7-98.
Closing a Smart Large Object Once you have finished the read and write operations on the smart large object, deallocate the resources assigned to it with the ifx_lo_close() function. When the resources are freed, they can be reallocated to other structures that your program needs. In addition, the LO file descriptor can be reallocated to other smart large objects. For more information on the ifx_lo_close() function, see page 7-38.