Oracle8i Application Developer's Guide - Large Objects (LOBs) Release 2 (8.1.6) Part Number A76940-01 |
|
Internal Persistent LOBs, 27 of 42
See:
"Use Case Model: Internal Persistent LOBs Basic Operations", for all basic operations of Internal Persistent LOBs. |
This procedure describes how to see if a LOB locator is initialized.
Not applicable.
See Chapter 3, "LOB Programmatic Environments" for a list of available functions in each programmatic environment. Use the following syntax references for each programmatic environment:
The operation allows you to determine if the locator has been initialized or not. In the example shown both locators are found to be initialized.
Examples are provided in the following programmatic environments:
/* Select the locator: */ sb4 select_frame_locator(Lob_loc, errhp, svchp, stmthp) OCILobLocator *Lob_loc; OCIError *errhp; OCISvcCtx *svchp; OCIStmt *stmthp; { text *sqlstmt = (text *)"SELECT Frame FROM Multimedia_tab WHERE Clip_ID=1"; OCIDefine *defnp1; checkerr (errhp, OCIStmtPrepare(stmthp, errhp, sqlstmt, (ub4)strlen((char *)sqlstmt), (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT)); checkerr (errhp, OCIDefineByPos(stmthp, &defnp1, errhp, (ub4) 1, (dvoid *)&Lob_loc, (sb4)0, (ub2) SQLT_BLOB,(dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) OCI_DEFAULT)); /* Execute the select and fetch one row: */ checkerr(errhp, OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0, (CONST OCISnapshot*) 0, (OCISnapshot*) 0, (ub4) OCI_DEFAULT)); return (0); } void isInitializedLob(envhp, errhp, svchp, stmthp) OCIEnv *envhp; OCIError *errhp; OCISvcCtx *svchp; OCIStmt *stmthp; { OCILobLocator *Lob_loc1, *Lob_loc2; boolean isInitialized; /* Allocate the LOB locators: */ printf(" allocate locator 1 and 2\n"); (void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &Lob_loc1, (ub4)OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); (void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &Lob_loc2, (ub4)OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0); /* Select the LOBs: */ printf (" select a frame locator into locator 1\n"); select_frame_locator(Lob_loc1, errhp, svchp, stmthp); /* locator 1 */ /* Determine if the locator 1 is Initialized -: */ checkerr(errhp, OCILobLocatorIsInit(envhp, errhp, Lob_loc1, &isInitialized)); /* IsInitialized should return TRUE here */ printf(" for Locator 1, isInitialized = %d\n", isInitialized); /* Determine if the locator 2 is Initialized -: */ checkerr(errhp, OCILobLocatorIsInit(envhp, errhp, Lob_loc2, &isInitialized)); /* IsInitialized should return FALSE here */ printf(" for Locator 2, isInitialized = %d\n", isInitialized); /* Free resources held by the locators: */ (void) OCIDescriptorFree((dvoid *) Lob_loc1, (ub4) OCI_DTYPE_LOB); (void) OCIDescriptorFree((dvoid *) Lob_loc2, (ub4) OCI_DTYPE_LOB); return; }
/* Pro*C/C++ has no form of embedded SQL statement to determine if a LOB locator is initialized. Locators in Pro*C/C++ are initialized when they are allocated via the EXEC SQL ALLOCATE statement. However, an example can be written that uses embedded SQL and the OCI as is shown here: */ #include <sql2oci.h> #include <stdio.h> #include <sqlca.h> void Sample_Error() { EXEC SQL WHENEVER SQLERROR CONTINUE; printf("%.*s\n", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc); EXEC SQL ROLLBACK WORK RELEASE; exit(1); } void LobLocatorIsInit_proc() { OCIBlobLocator *Lob_loc; OCIEnv *oeh; OCIError *err; boolean isInitialized; EXEC SQL WHENEVER SQLERROR DO Sample_Error(); EXEC SQL ALLOCATE :Lob_loc; EXEC SQL SELECT Frame INTO Lob_loc FROM Multimedia_tab where Clip_ID = 1; /* Get the OCI Environment Handle using a SQLLIB Routine: */ (void) SQLEnvGet(SQL_SINGLE_RCTX, &oeh); /* Allocate the OCI Error Handle: */ (void) OCIHandleAlloc((dvoid *)oeh, (dvoid **)&err, (ub4)OCI_HTYPE_ERROR, (ub4)0, (dvoid **)0); /* Use the OCI to determine if the locator is Initialized: */ (void) OCILobLocatorIsInit(oeh, err, Lob_loc, &isInitialized); if (isInitialized) printf("The locator is initialized\n"); else printf("The locator is not initialized\n"); /* Note that in this example, the locator is initialized */ /* Deallocate the OCI Error Handle: */ (void) OCIHandleFree(err, OCI_HTYPE_ERROR); /* Release resources held by the locator: */ EXEC SQL FREE :Lob_loc; } void main() { char *samp = "samp/samp"; EXEC SQL CONNECT :samp; LobLocatorIsInit_proc(); EXEC SQL ROLLBACK WORK RELEASE; }
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|