Skip to content

SQLTrimLob

SQLTrimLob#

This function deletes the latter portion of data from a specified position, of the LOB value that the LOB locater points to.

Syntax#

SQLRETURN SQLTrimLob(
    SQLHSTMT         stmt,
    SQLSMALLINT      locatorCType,
    SQLUBIGINT       targetLocator,
    SQLLEN           fromPosition);

Arguments#

Data Type Argument In/Output Description
SQLHSTMT stmt Input The handle for the found results.
SQLSMALLINT locatorCType Input The C data type identifier of the target LOB locator.
- SQL_C_BLOB_LOCATOR
- SQL_C_CLOB_LOCATOR
SQLUBIGINT targetLocator Input Target LOB Locator
SQLLEN fromPosition Input The position at which to start deleting LOB data (unit:bytes). Begins at 0.

Result Values#

SQL_SUCCESS
SQL_INVALID_HANDLE
SQL_ERROR

Description#

This function deletes the latter portion of data from a specified position, of the LOB value that the LOB locater points to. After deletion, the length of the target LOB is shortened.

If the LOB locator is not one which is opened in the current session, it is not accepted as an argument for this function, since the LOB locator becomes invalid when the transaction terminates. If the target LOB locator is invalid, the SQLTrimLob() function returns SQL_ERROR.

Diagnosis#

SQLSTATE Description Comments
08S01 Communication link fault (Data transmission failure) A communication link failed before function processing is complete between Altibase CLI driver and DB.
HY000 General error
SQLGetLobLength
SQLGetLob

Examples#

It is assumed that a table is created with the following DDL.

CREATE TABLE T1 (i1 INTEGER PRIMARY KEY, i2 CLOB);

After inserting a record with the CLOB column value 'Ver.Beta', delete 'Beta'#

SQLCHAR buf[5];
SQLUBIGINT lobLoc;

strcpy(query, "INSERT INTO T1 VALUES (1, 'Ver.Beta')");
if (SQLExecDirect(stmt, query, SQL_NTS) != SQL_SUCCESS)
{
     execute_err(dbc, stmt, "SQLExecDirect : ");
     SQLFreeStmt(stmt, SQL_DROP);
     return SQL_ERROR;
}

strcpy(query, "SELECT i2 FROM T1 WHERE i1=1 FOR UPDATE");
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 (SQLTrimLob(stmt, SQL_C_CLOB_LOCATOR, lobLoc, 4) != SQL_SUCCESS)
{
     execute_err(dbc, stmt, "SQLTrimLob : ");
     SQLFreeStmt(stmt, SQL_DROP);
     return SQL_ERROR;
}
if (SQLFreeLob(stmt, lobLoc) != SQL_SUCCESS)
{
     execute_err(dbc, stmt, "SQLFreeLob : ");
     SQLFreeStmt(stmt, SQL_DROP);
     return SQL_ERROR;
}