4D v16

Reading from a LONG RAW column

Inicio

 
4D v16
Reading from a LONG RAW column

Reading from a LONG RAW column  


 

 

You can use 4D for OCI to read the contents of a LONG RAW column in an Oracle database under the following conditions:

  1. the receiving variable must be of the BLOB type
  2. the datatype must be SQLT_LBI
  3. the mode must be OCI_DYNAMIC_FETCH (and not OCI_DEFAULT)

Ejemplo  


  //Method: Read_long_raw
  //reads data from a long raw column
  //and creates the picture file (jpg) in the database folder
 
 C_LONGINT(envhp;errhp;svchp;vDefine;stmthp;stmtSelecthp)
 C_LONGINT(RealLength)
 C_BLOB(TheBlob)
 
  //--------------------------------------------
  //CONDITION 1: Blob
 SET BLOB SIZE(TheBlob;0)
  //--------------------------------------------
 
 C_POINTER(vp_Null1;vp_Null3)
 ReadLength:=0
 
 C_TEXT($UserName;$Password;$ServiceName;$SQL_statement)
 
 $UserName:="xxx"
 $Password:="xxx"
 $ServiceName:="xxx"
 
 Status:=OCIEnvCreate(envhp;OCI_OBJECT)
 Status:=OCIHandleAlloc(envhp;errhp;OCI_HTYPE_ERROR)
 Status:=OCILogon(envhp;errhp;svchp;$UserName;$Password;$ServiceName)
 Status:=OCIHandleAlloc(envhp;stmthp;OCI_HTYPE_STMT)
 
 $SQL_statement:="SELECT lgraw FROM test_LGRAW WHERE key = 20"
 Status:=OCIHandleAlloc(envhp;stmtSelecthp;OCI_HTYPE_STMT)
 If(Status=OCI_SUCCESS)
    Status:=OCIStmtPrepare(stmtSelecthp;errhp;$SQL_statement;OCI_DEFAULT)
 
  //--------------------------------------------
  //CONDITION 2: SQLT_LBI for LONG RAW
  //CONDITION 3: OCI_DYNAMIC_FETCH instead of OCI_DEFAULT
 
    Status:=OCIDefineByPos(stmtSelecthp;vDefine;errhp;1;->TheBlob;SQLT_LBI;vp_Null1;
    ->ReadLength;vp_Null3;OCI_DYNAMIC_FETCH)
  //--------------------------------------------
 
    $status:=OCIErrorGet(errhp;1;$errornum;$errorexplain)
    If($errornum#0)
       ALERT(String($errornum)+Char(13)+$errorexplain)
    End if
    Repeat
       Status:=OCIStmtExecute(svchp;stmtSelecthp;errhp;1;0;0;0;OCI_DEFAULT)
    Until(Status#OCI_STILL_EXECUTING)
    Status:=OCIHandleFree(stmtSelecthp)
 End if
 
  //remove the first 8 characters if the picture was inserted with 4D for Oracle
 DELETE FROM BLOB(TheBlob;0;8)
 
 If(ReadLength>0)
    $DocRef:=Create document("longraw_image.jpg")
    If(OK=1)
       CLOSE DOCUMENT($DocRef)
       BLOB TO DOCUMENT(Document;TheBlob)
    End if
 Else
    ALERT("Blob size: zero!")
 End if
 
 Status:=OCIHandleFree(stmthp)
 Status:=OCILogoff(svchp;errhp)
 Status:=OCIHandleFree(errhp)
 Status:=OCIHandleFree(envhp)
 
 SET BLOB SIZE(TheBlob;0) //empty Blob
 
  //End of method

 
PROPIEDADES 

Producto: 4D
Tema: Ejemplos de uso

 
HISTORIA 

 
ARTICLE USAGE

4D for OCI ( 4D v16)