Call Level Interface Guide and Reference

SQLGetPosition - Return Starting Position of String

Purpose


Specification: DB2 CLI 2.1    

SQLGetPosition() is used to return the starting position of one string within a LOB value (the source). The source value must be a LOB locator, the search string can be a LOB locator or a literal string.

The source and search LOB locators can be any that have been returned from the database from a fetch or a SQLGetSubString() call during the current transaction.

Syntax

SQLRETURN   SQLGetPosition   (SQLHSTMT          StatementHandle,   /* hstmt */
                              SQLSMALLINT       LocatorCType,
                              SQLINTEGER        SourceLocator,
                              SQLINTEGER        SearchLocator,
                              SQLCHAR      FAR  *SearchLiteral,
                              SQLINTEGER        SearchLiteralLength,
                              SQLUINTEGER       FromPosition,
                              SQLUINTEGER  FAR  *LocatedAt,
                              SQLINTEGER   FAR  *IndicatorValue);

Function Arguments


Table 115. SQLGetPosition Arguments
Data Type Argument Use Description
SQLHSTMT StatementHandle input Statement handle. This can be any statement handle which has been allocated but which does not currently have a prepared statement assigned to it.
SQLSMALLINT LocatorCType input The C type of the source LOB locator. This may be:
  • SQL_C_BLOB_LOCATOR
  • SQL_C_CLOB_LOCATOR
  • SQL_C_DBCLOB_LOCATOR
SQLINTEGER Locator input Locator must be set to the source LOB locator.
SQLINTEGER SearchLocator input If the SearchLiteral pointer is NULL and if SearchLiteralLength is set to 0, then SearchLocator must be set to the LOB locator associated with the search string; otherwise, this argument is ignored.
SQLCHAR * SearchLiteral input This argument points to the area of storage that contains the search string literal.

If SearchLiteralLength is 0, this pointer must be NULL.

SQLINTEGER SearchLiteralLength input The length of the string in SearchLiteral(in bytes). a

If this argument value is 0, then the argument SearchLocator is meaningful.

SQLUINTEGER FromPosition input For BLOBs and CLOBs, this is the position of the first byte within the source string at which the search is to start. to be returned by the function. For DBCLOBs, this is the first character. The start byte or character is numbered 1.
SQLUINTEGER * LocatedAt output For BLOBs and CLOBs, this is the byte position at which the string was located or, if not located, the value zero. For DBCLOBs, this is the character position.

If the length of the source string is zero, the value 1 is returned.

SQLINTEGER * IndicatorValue output Always set to zero.
Note:

a
This is in bytes even for DBCLOB data.

Usage

SQLGetPosition() is used in conjunction with SQLGetSubString() in order to obtain any portion of a string in a random manner. In order to use SQLGetSubString(), the location of the substring within the overall string must be known in advance. In situations where the start of that substring can be found by a search string, SQLGetPosition() can be used to obtain the starting position of that substring.

The Locator and SearchLocator (if used) arguments can contain any valid LOB locator which has not been explicitly freed using a FREE LOCATOR statement or implicitly freed because the transaction during which it was created has terminated.

The Locator and SearchLocator must have the same LOB locator type.

The statement handle must not have been associated with any prepared statements or catalog function calls.

Return Codes

Diagnostics


Table 116. SQLGetPosition SQLSTATEs
SQLSTATE Description Explanation
07006 Invalid conversion. The combination of LocatorCType and either of the LOB locator values is not valid.
40003 08S01 Communication link failure. The communication link between the application and data source failed before the function completed.
42818 The operands of an operator or function are not compatible. The length of the pattern is longer than 4000 bytes.
58004 Unexpected system failure. Unrecoverable system error.
HY001 Memory allocation failure. DB2 CLI is unable to allocate memory required to support execution or completion of the function.
HY009 Invalid argument value. The pointer to the LocatedAt argument was NULL.

The argument value for FromPosition was not greater than 0.

LocatorCType is not one of SQL_C_CLOB_LOCATOR, SQL_C_BLOB_LOCATOR, or SQL_C_DBCLOB_LOCATOR.

HY010 Function sequence error. The specified StatementHandle is not in an allocated state.

The function was called while in a data-at-execute (SQLParamData(), SQLPutData()) operation.

The function was called while within a BEGIN COMPOUND and END COMPOUND SQL operation.

An asynchronously executing function (not this one) was called for the StatementHandle and was still executing when this function was called.

HY013 Unexpected memory handling error. DB2 CLI was unable to access memory required to support execution or completion of the function.
HY090 Invalid string or buffer length. The value of SearchLiteralLength was less than 1, and not SQL_NTS.
HYC00 Driver not capable. The application is currently connected to a data source that does not support large objects.
0F001 The LOB token variable does not currently represent any value. The value specified for Locator or SearchLocator is not currently a LOB locator.

Restrictions

This function is not available when connected to a DB2 server that does not support Large Objects. Call SQLGetFunctions() with the function type set to SQL_API_SQLGETPOSITION and check the fExists output argument to determine if the function is supported for the current connection.

CLI Sample dtlob.c

(The complete sample dtlob.c is also available here .)

 
/* From the CLI sample dtlob.c */
/* ... */
 
    /* get the starting postion of the CLOB piece of data */
    sqlrc = SQLGetPosition( hstmtLocUse,
                            SQL_C_CLOB_LOCATOR,
                            clobLoc,
                            0,
                            ( SQLCHAR * ) "Interests",
                            strlen( "Interests"),
                            1,
                            &clobPiecePos,
                            &ind ) ;
    
 

References


[ Top of Page | Previous Page | Next Page ]