Oracle9i Application Developer's Guide - Large Objects (LOBs)
Release 1 (9.0.1)

Part Number A88879-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Temporary LOBs, 18 of 29


Is One Temporary LOB Locator Equal to Another

Figure 11-16 Use Case Diagram: Is One (Temporary) LOB Locator Equal to Another


Text description of adl11tm4.gif follows This link takes you back to the Internal Temporary LOBs main model diagram.
Text description of the illustration adl11tm4.gif

See:

"Use Case Model: Internal Temporary LOBs", for all basic operations of Internal Temporary LOBs. 

Purpose

This procedure describes how to see if one LOB locator for a temporary LOB is equal to another.

Usage Notes

If two locators are equal they refer to the same version of the LOB data (see "Read Consistent Locators" in Chapter 5, "Large Objects: Advanced Topics").

Syntax

See Chapter 3, "LOB Support in Different Programmatic Environments" for a list of available functions in each programmatic environment. Use the following syntax references for each programmatic environment:

Scenario

Not applicable.

Examples

Examples are provided in the following programmatic environments:

C (OCI): Is One LOB Locator for a Temporary LOB Equal to Another

sb4 ck_isequal (OCIError      *errhp,
                OCISvcCtx     *svchp,
                OCIStmt       *stmthp,
                OCIEnv        *envhp)
{
  OCILobLocator *loc1;
  OCILobLocator *loc2;
  boolean is_equal;
  is_equal= FALSE;
OCILobDescriptor ????
  if(OCILobCreateTemporary(svchp, errhp, loc1, (ub2)0, SQLCS_IMPLICIT,
                           OCI_TEMP_BLOB, OCI_ATTR_NOCACHE, 
                           OCI_DURATION_SESSION))
  {
     (void) printf("FAILED: CreateTemporary() \n");
     return -1;
  } 
   if(OCILobCreateTemporary(svchp, errhp, loc2, (ub2)0, SQLCS_IMPLICIT,
                            OCI_TEMP_BLOB, OCI_ATTR_NOCACHE, 
                            OCI_DURATION_SESSION))
  {
     (void) printf("FAILED: CreateTemporary() \n");
     return -1;
  } 

  if (OCILobIsEqual(envhp,loc1,loc2, &is_equal))
  {
    printf ("FAILED: OCILobLocatorIsEqual call\n");
    return -1;
  }
  if(is_equal)
  {
      fprintf (stderr,"LOB loators are equal \n");
      return -1;
 
   }else
   {
      fprintf(stderr,"LOB locators are not equal \n");
   }
   if(OCILobFreeTemporary(svchp,errhp,loc1))
   {
        printf("FAILED: OCILobFreeTemporary for temp LOB #1\n");
        return -1;
   }
  if(OCILobFreeTemporary(svchp,errhp,loc2))
   {
        printf("FAILED: OCILobFreeTemporary for temp LOB #2\n");
        return -1;
   }
OCILobDescriptor free????
   return 0;
  }

C/C++ (Pro*C/C++): Is One LOB Locator for a Temporary LOB Equal to Another

This script is also located at $ORACLE_HOME/rdbms/demo/lobs/proc/tequal

#include <sql2oci.h>
#include <stdio.h>
#include <sqlca.h>

void Sample_Error()
{
  EXEC SQL WHENEVER SQLERROR CONTINUE;
  printf("sqlcode = %ld\n", sqlca.sqlcode);
  printf("%.*s\n", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
  EXEC SQL ROLLBACK WORK RELEASE;
  exit(1);
}

void seeTempLobLocatorsAreEqual_proc()
{
  OCIBlobLocator *Temp_loc1, *Temp_loc2; 
  OCIBFileLocator *Lob_loc; 
  char *Dir = "AUDIO_DIR", *Name = "Washington_audio"; 
  int Amount = 4096; 
  OCIEnv *oeh; 
  int isEqual = 0; 

  EXEC SQL WHENEVER SQLERROR DO Sample_Error(); 
  /* Allocate and Create the Temporary LOBs: */ 
  EXEC SQL ALLOCATE :Temp_loc1; 
  EXEC SQL ALLOCATE :Temp_loc2; 
  EXEC SQL LOB CREATE TEMPORARY :Temp_loc1; 
  EXEC SQL LOB CREATE TEMPORARY :Temp_loc2; 
  /* Allocate and Initialize the BFILE Locator: */ 
  EXEC SQL ALLOCATE :Lob_loc; 
  EXEC SQL LOB FILE SET :Lob_loc DIRECTORY = :Dir, FILENAME = :Name; 
  /* Opening the LOBs is Optional: */ 
  EXEC SQL LOB OPEN :Lob_loc READ ONLY; 
  EXEC SQL LOB OPEN :Temp_loc1 READ WRITE; 
  EXEC SQL LOB OPEN :Temp_loc2 READ WRITE; 
  
  /* Load a specified amount from the BFILE into one of the Temporary LOBs: */ 
  EXEC SQL LOB LOAD :Amount FROM FILE :Lob_loc INTO :Temp_loc1; 
  /* Retrieve the OCI Environment Handle: */ 
  (void) SQLEnvGet(SQL_SINGLE_RCTX, &oeh); 
  
  /* Now assign Temp_loc1 to Temp_loc2 using Embedded SQL: */ 
  EXEC SQL LOB ASSIGN :Temp_loc1 TO :Temp_loc2; 
  
  /* Determine if the Temporary LOBs are Equal: */ 
  (void) OCILobIsEqual(oeh, Temp_loc1, Temp_loc2, &isEqual); 
  
  /* This time, isEqual should be 0 (FALSE): */ 
  printf("Locators %s equal\n", isEqual ? "are" : "are not"); 
  
  /* Assign Temp_loc1 to Temp_loc2 using C pointer assignment: */ 
  Temp_loc2 = Temp_loc1; 
  
  /* Determine if the Temporary LOBs are Equal again: */ 
  (void) OCILobIsEqual(oeh, Temp_loc1, Temp_loc2, &isEqual); 
  
  /* The value of isEqual should be 1 (TRUE) in this case: */ 
  printf("Locators %s equal\n", isEqual ? "are" : "are not"); 
  
  /* Closing the LOBs is Mandatory if they have been Opened: */ 
  EXEC SQL LOB CLOSE :Lob_loc;    
  /* Note that because Temp_loc1 and Temp_loc2 are now equal, closing
     and freeing one will implicitely do the same to the other: */
  EXEC SQL LOB CLOSE :Temp_loc1;  
  EXEC SQL LOB FREE TEMPORARY :Temp_loc1;  
  /* Release resources held by the Locators: */ 
  EXEC SQL FREE :Lob_loc; 
  EXEC SQL FREE :Temp_loc1; 
}

void main()
{
  char *samp = "samp/samp";
  EXEC SQL CONNECT :samp;
  seeTempLobLocatorsAreEqual_proc();
  EXEC SQL ROLLBACK WORK RELEASE;
}



Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback