SQLGetLob
SQLGetLob#
SQLGetLob gets a part of data in the LOB pointed by the LOB locator obtained during the current transaction to an application data buffer.
Syntax#
SQLRETURN SQLGetLob(
SQLHSTMT stmt,
SQLSMALLINT locatorCType,
SQLUBIGINT sourceLocator,
SQLUINTEGER fromPosition,
SQLUINTEGER forLength,
SQLSMALLINT targetCType,
SQLPOINTER value,
SQLUINTEGER bufferSize,
SQLUINTEGER * valueLength);
Arguments#
Data Type | Argument | In/Output | Description |
---|---|---|---|
SQLHSTMT | stmt | Input | Handle for the found results. |
SQLSMALLINT | locatorCType | Input | The C data type identifier of a LOB locator. It can have the following values: - SQL_C_BLOB_LOCATOR - SQL_C_CLOB_LOCATOR |
SQLUBIGINT | sourceLocator | Input | Source LOB Locator |
SQLUINTEGER | fromPosition | Input | The start point of data to transfer from LOB (byte). It begins at 1. |
SQLUINTEGER | forLength | Input | The length of data to transfer from LOB (byte). |
SQLSMALLINT | targetCType | Input | The C data type identifier of the value buffer. It can have the following values: - SQL_C_BINARY - SQL_C_CHAR If the user reads BLOB data into the SQL_C_CHAR buffer, BINARY is converted to CHAR, and the result value is stored in an application buffer. |
SQLPOINTER | value | Output | A pointer to the buffer that holds data. |
SQLUINTEGER | bufferSize | Input | The size of the value buffer (byte). |
SQLUINTEGER* | valueLength | Output | A pointer to the buffer to which the length of data stored in the value buffer is returned. This argument cannot be NULL. |
Result Values#
SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR
Description#
Gets a part of data in the LOB pointed by the source locator to an application data buffer. It is used to get LOB data in parts. The total length of LOB can be obtained by calling SQLGetLobLength().
If a source locator is not the LOB locator obtained during the current transaction, it cannot be used as an argument for this function. This is because a LOB locator becomes invalid if a transaction is terminated. If a source LOB locator is not valid, the SQLGetLob() function will return SQL_ERROR, and the buffer pointed by the value and valueLength arguments will not be changed.
If a source locator points NULL LOB, the SQLGetLob() function works in the same way as when a LOB locator points LOB with length 0.
If the size of data that will be returned by calling SQLGetLob() exceeds the size of bufferSize, the SQLGetLob() will return SQL_SUCCESS_WITH_INFO (SQLSTATE=01004), and the data will be truncated to fit the buffer size before it is returned to the buffer.
Diagnosis#
SQLSTATE | Description | Comments |
---|---|---|
08S01 | Communication link fault (Data transmission failure) | Communication link failed before function processing is complete between Altibase CLI driver and DB. |
HY000 | General error |
Related Functions#
SQLGetLobLength
SQLPutLob
Example#
It is assumed that a table has been created with the following DDL.
CREATE TABLE T1 (i1 INTEGER PRIMARY KEY, i2 CLOB);
Retrieve LOB data to an application buffer by using the SQLGetLob() function#
SQLCHAR buf[1024];
SQLINTEGER valueLength, accumLength, forLength, procLength;
SQLUBIGINT lobLoc;
.
.
strcpy(query, "SELECT i2 FROM T1 WHERE i1=1");
if (SQLExecDirect(stmt, query, SQL_NTS) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLExecDirect : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLBindCol(stmt, 1, SQL_C_CLOB_LOCATOR, &lobLoc, 0, NULL) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLBindCol : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLFetch(stmt) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLFetch : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
if (SQLGetLobLength(stmt, lobLoc, SQL_C_CLOB_LOCATOR, &valueLength) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLGetLobLength : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
for (accumLength = 0; accumLength < valueLength; accumLength += procLength)
{
if (valueLength - accumLength > 256)
{
forLength = 256;
}
else
{
forLength = valueLength - accumLength;
}
if (SQLGetLob(stmt, SQL_C_CLOB_LOCATOR, lobLoc, accumLength, forLength, SQL_C_CHAR, buf, 256, &procLength) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLGetLob : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}
printf("%s", buf);
}
if (SQLFreeLob(stmt, lobLoc) != SQL_SUCCESS)
{
execute_err(dbc, stmt, "SQLFreeLob : ");
SQLFreeStmt(stmt, SQL_DROP);
return SQL_ERROR;
}