LOB および LOB ロケーターの例
アプリケーションは、アプリケーション・アドレス・スペースで LOB 値を使用できます。これらの値をデータベース・サーバーで識別し取り扱うのに LOB ロケーターは役に立ちます。
以下の例は、EMP_RESUME 表の RESUME CLOB 列 から 'Interests' セクションを抜き出すアプリケーションを示しています。このアプリケーションでは、サブストリングをメモリーの中に転送するだけです。
/* ... */
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_INPUT, SQL_C_CHAR, SQL_CHAR, 7,
0, Empno.s, sizeof(Empno.s), &Empno.ind);
printf("¥n>Enter an employee number:¥n");
gets(Empno.s);
rc = SQLExecDirect(hstmt, stmt2, SQL_NTS);
rc = SQLBindCol(hstmt, 1, SQL_C_CLOB_LOCATOR, &ClobLoc1, 0,
&pcbValue);
rc = SQLFetch(hstmt);
/******************************************************************
Search CLOB locator to find "Interests"
Get substring of resume (from position of interests to end)
*******************************************************************/
rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &lhstmt);
/* Get total length */
rc = SQLGetLength(lhstmt, SQL_C_CLOB_LOCATOR, ClobLoc1, &SLength, &Ind);
/* Get starting position */
rc = SQLGetPosition(lhstmt, SQL_C_CLOB_LOCATOR, ClobLoc1, 0,
"Interests", 9, 1, &Pos1, &Ind);
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);
/* Print Interest section of Employee's resume */
printf("¥nEmployee #:
/* ... */