When manipulating long data, it may not be feasible for the application to load the entire parameter data value into storage at the time the statement is executed, or when the data is fetched from the database. A method has been provided to allow the application to handle the data in a piecemeal fashion. The technique to send long data in pieces is called Specifying Parameter Values at Execute Time because it can also be used to specify values for fixed size non-character data types such as integers.
An application can also use the SQLGetSubString() function to retrieve a portion of a large object value. See Figure 16 in Using Large Objects for details.
A bound parameter for which value is prompted at execution time instead of stored in memory before calling SQLExecute() or SQLExecDirect() is called a data-at-execute parameter. To indicate such a parameter on an SQLBindParameter() call, the application:
If there are any data-at-execute parameters when the application calls SQLExecDirect() or SQLExecute(), the call returns with SQL_NEED_DATA to prompt the application to supply values for these parameters. The application responds as follows:
When all data-at-execute parameters have been assigned values, SQLParamData() completes execution of the SQL statement and produces a return value and diagnostics as the original SQLExecDirect() or SQLExecute() would have produced. The right side of Figure 9 illustrates this flow.
While the data-at-execution flow is in progress, the only DB2 CLI functions the application can call are:
Using the parameter at execute time technique to input Large Object data may require the creation and use of a temporary file at the client. For alternative methods to input long data, refer to Using Large Objects.
Typically, based on its knowledge of a column in the result set (via SQLDescribeCol() or prior knowledge), the application may choose to allocate the maximum memory the column value could occupy and bind it via SQLBindCol(). However, in the case of character and binary data, the column can be arbitrarily long. If the length of the column value exceeds the length of the buffer the application can allocate or afford to allocate, a feature of SQLGetData() lets the application use repeated calls to obtain in sequence the value of a single column in more manageable pieces.
Basically, as shown on the left side of Figure 9, a call to SQLGetData() returns SQL_SUCCESS_WITH_INFO (with SQLSTATE 01004) to indicate more data exists for this column. SQLGetData() is called repeatedly to get the remaining pieces of data until it returns SQL_SUCCESS, signifying that the entire data have been retrieved for this column.
The function SQLGetSubString() can also be used to retrieve a specific portion of a large object value. See SQLGetSubString - Retrieve Portion of A String Value for more information. For other alternative methods to retrieve long data, refer to Using Large Objects.
Figure 9. Piecewise Input and Retrieval
For an example of piecewise input of an image blob refer to picin2.c, shown in Example.
For an example of piecewise retrieval of an image blob refer to showpic2.c, shown in Example.