IBM Books

Call Level Interface Guide and Reference

LOB Examples

The following example extracts the "Interests" section from the Resume CLOB column of the EMP_RESUME table. Only the substring is transferred to the application.

/* From CLI sample lookres.c */
/* ... */
    SQLCHAR * stmt2 = "SELECT resume FROM emp_resume "
                      "WHERE empno = ?  AND resume_format = 'ascii'" ;
/* ... */
    /* Get CLOB locator to selected Resume */
 
    rc = SQLBindParameter( hstmt,
                           1,
                           SQL_PARAM_OUTPUT,
                           emp_no.type,
                           SQL_CHAR,
                           emp_no.length,
                           0,
                           emp_no.s,
                           emp_no.length,
                           &emp_no.ind
                         ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
 
    printf( "\n>Enter an employee number:\n" ) ;
    gets( ( char * ) emp_no.s ) ;
 
    rc = SQLExecDirect( hstmt, stmt2, SQL_NTS ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
 
    rc = SQLBindCol( hstmt,
                     1,
                     SQL_C_CLOB_LOCATOR,
                     &ClobLoc1,
                     0,
                     &pcbValue
                   ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
 
    rc = SQLFetch( hstmt ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ;
 
    /*
     Search CLOB locator to find "Interests"
     Get substring of resume ( from position of interests to end )
    */
 
    rc = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &lhstmt ) ;
    CHECK_HANDLE( SQL_HANDLE_DBC, hdbc, rc ) ;
 
    /* Get total length */
    rc = SQLGetLength( lhstmt,
                       SQL_C_CLOB_LOCATOR,
                       ClobLoc1,
                       &SLength,
                       &Ind ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, lhstmt, rc ) ;
 
    /* Get Starting postion */
    rc = SQLGetPosition( lhstmt,
                         SQL_C_CLOB_LOCATOR,
                         ClobLoc1,
                         0,
                         ( SQLCHAR * ) "Interests",
                         9,
                         1,
                         &Pos1,
                         &Ind
                       ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, lhstmt, rc ) ;
 
    rc = SQLFreeStmt( lhstmt, SQL_CLOSE ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, lhstmt, rc ) ;
 
    buffer = ( SQLCHAR * ) malloc( SLength - Pos1 + 1 ) ;
 
    /* Get just the "Interests" section of the Resume CLOB */
    /* ( From Pos1 to end of CLOB ) */
    rc = SQLGetSubString( lhstmt,
                          SQL_C_CLOB_LOCATOR,
                          ClobLoc1,
                          Pos1,
                          SLength - Pos1,
                          SQL_C_CHAR,
                          buffer,
                          SLength - Pos1 + 1,
                          &OutLength,
                          &Ind
                        ) ;
    CHECK_HANDLE( SQL_HANDLE_STMT, lhstmt, rc ) ;
    /* Print Interest section of Employee's resume */
    printf( "\nEmployee #: %s\n %s\n", emp_no.s, buffer ) ;


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]