Oracle8i Application Developer's Guide - Large Objects (LOBs) Release 2 (8.1.6) Part Number A76940-01 |
|
External LOBs (BFILEs), 31 of 41
See Also:
"Use Case Model: External LOBs (BFILEs)" for all basic operations of External LOBs (BFILES). |
This procedure describes how to see if one BFILE LOB locator is equal to another.
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:
If two locators are equal, this means that they refer to the same version of the LOB
data (see "Read-Consistent Locators" in Chapter 5, "Advanced Topics").
The examples are provided in the following three programmatic environments:
/* Select the lob/bfile from the Multimedia table */ void selectLob(Lob_loc, errhp, svchp, stmthp) OCILobLocator *Lob_loc; OCIError *errhp; OCISvcCtx *svchp; OCIStmt *stmthp; { OCIDefine *dfnhp; text *selstmt = (text *) "SELECT Photo FROM Multimedia_tab \ WHERE Clip_ID = 3"; /* Prepare the SQL select statement */ checkerr (errhp, OCIStmtPrepare(stmthp, errhp, selstmt, (ub4) strlen((char *) selstmt), (ub4) OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT)); /* Call define for the bfile column */ checkerr (errhp, OCIDefineByPos(stmthp, &dfnhp, errhp, 1, (dvoid *)&Lob_loc, 0 , SQLT_BFILE, (dvoid *)0, (ub2 *)0, (ub2 *)0, OCI_DEFAULT)); /* Execute the SQL select statement */ checkerr (errhp, OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0, (CONST OCISnapshot*) 0, (OCISnapshot*) 0, (ub4) OCI_DEFAULT)); } void BfileIsEqual(envhp, errhp, svchp, stmthp) OCIEnv *envhp; OCIError *errhp; OCISvcCtx *svchp; OCIStmt *stmthp; { OCILobLocator *bfile_loc1; OCILobLocator *bfile_loc2; boolean is_equal; /* Allocate the locator descriptors */ (void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &bfile_loc1, (ub4) OCI_DTYPE_FILE, (size_t) 0, (dvoid **) 0); (void) OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &bfile_loc2, (ub4) OCI_DTYPE_FILE, (size_t) 0, (dvoid **) 0); /* Select the bfile */ selectLob(bfile_loc1, errhp, svchp, stmthp); checkerr(errhp, OCILobLocatorAssign(svchp, errhp, bfile_loc1, &bfile_loc2)); checkerr(errhp, OCILobIsEqual(envhp, bfile_loc1, bfile_loc2, &is_equal)); if (is_equal == TRUE) { printf("Locators are equal\n"); } else { printf("Locators are not equal\n"); } /* Free the locator descriptor */ OCIDescriptorFree((dvoid *)bfile_loc1, (ub4)OCI_DTYPE_FILE); OCIDescriptorFree((dvoid *)bfile_loc2, (ub4)OCI_DTYPE_FILE); }
/* Pro*C/C++ does not provide a mechanism to test the equality of two locators However, by using the OCI directly, two locators can be compared to determine whether or not they are equal as this example demonstrates: */ #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 BFILELocatorIsEqual_proc() { OCIBFileLocator *Lob_loc1, *Lob_loc2; OCIEnv *oeh; boolean isEqual = 0; EXEC SQL WHENEVER SQLERROR DO Sample_Error(); EXEC SQL ALLOCATE :Lob_loc1; EXEC SQL ALLOCATE :Lob_loc2; EXEC SQL SELECT Photo INTO :Lob_loc1 FROM Multimedia_tab WHERE Clip_ID = 3; EXEC SQL LOB ASSIGN :Lob_loc1 TO :Lob_loc2; /* Now you can read the BFILE from either Lob_loc1 or Lob_loc2 */ /* Get the OCI Environment Handle using a SQLLIB Routine: */ (void) SQLEnvGet(SQL_SINGLE_RCTX, &oeh); /* Call OCI to see if the two locators are Equal: */ (void) OCILobIsEqual(oeh, Lob_loc1, Lob_loc2, &isEqual); if (isEqual) printf("Locators are equal\n"); else printf("Locators are not equal\n"); /* Note that in this example, the LOB locators will be Equal: */ EXEC SQL FREE :Lob_loc1; EXEC SQL FREE :Lob_loc2; } void main() { char *samp = "samp/samp"; EXEC SQL CONNECT :samp; BFILELocatorIsEqual_proc(); EXEC SQL ROLLBACK WORK RELEASE;}
import java.sql.Connection; import java.sql.Types; import java.sql.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; // Oracle Specific JDBC classes: import oracle.sql.*; import oracle.jdbc.driver.*; public class Ex4_89 { public static void main (String args []) throws Exception { // Load the Oracle JDBC driver: DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database: Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "samp", "samp"); // It's faster when auto commit is off: conn.setAutoCommit (false); // Create a Statement: Statement stmt = conn.createStatement (); try { BFILE lob_loc1 = null; BFILE lob_loc2 = null; ResultSet rset = stmt.executeQuery ( "SELECT photo FROM multimedia_tab WHERE clip_id = 3"); if (rset.next()) { lob_loc1 = ((OracleResultSet)rset).getBFILE (1); } // Set both LOBS to reference the same BFILE: lob_loc2 = lob_loc1; // Note that in this example, the Locators will be equal: if (lob_loc1.equals(lob_loc2)) { // The Locators are equal: System.out.println("The BFILEs are equal"); } else { // The Locators are different: System.out.println("The BFILEs are NOT equal"); } stmt.close(); conn.commit(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|