Read (OraLOB/BFILE) Method

Description

Reads into a buffer a specified portion of a BLOB, CLOB, or BFILE value. Returns the total amount of data read.

Usage

amount_read = OraBlob.Read buffer, chunksize
amount_read = OraClob.Read buffer, chunksize
amount_read = OraBfile.Read buffer, chunksize

Arguments

The arguments for the method are:

Arguments Description
[out] buffer Variant of type character array for OraCLOB, Variant of type byte array for OraBLOB, or OraBFILE from which the piece is read.
[in] [optional] chunksize An Integer specifying the amount to be read. Default value is the size of the LOB. In bytes for OraBLOB or OraBFILE; characters for OraCLOB.
[out] amount_read An Integer representing the total amount of data read. In bytes for OraBLOB or OraBFILE; characters for OraCLOB.

Remarks

Reads the LOB or BFILE data from the offset specified by the Offset property. For multiple piece read operation, the PollingAmount property must be set to the value of the total amount of data to be read, and the Status property must be checked for the success of each piece operation.

Note:

When reading a portion of a LOB, it is recommended that you set the PollingAmount property, rather than using the chunksize parameter. This avoids the possibility of raising an error if the entire LOB is not read before to executing another LOB method.

Examples

Be sure that you have installed the OraLOB Schema Objects as described in "Schema Objects Used in LOB Data Type Examples" .

Example: Multiple-Piece Read of a LOB

Dim OraSession As OraSession 
Dim OraDatabase As OraDatabase 
Dim OraDynaset As OraDynaset 
Dim PartImage As OraBlob 
Dim chunksize As Long 
Dim AmountRead As Long 
Dim buffer As Variant 
Dim buf As String 
 
'Create the OraSession Object. 
Set OraSession = CreateObject("OracleInProcServer.XOraSession") 
 
'Create the OraDatabase Object by opening a connection to Oracle. 
Set OraDatabase = OraSession.OpenDatabase("ExampleDb","scott/tiger", 0&)  
 
'Create the OraDynaset Object. 
Set OraDynaset = OraDatabase.CreateDynaset("select * from part", 0&) 
 
'Get OraBlob from OraDynaset 
Set PartImage = OraDynaset.Fields("part_image").Value 
 
'Set Offset and PollingAmount property for piecewise Read operation 
PartImage.offset = 1 
PartImage.PollingAmount = PartImage.Size 
chunksize = 50000 
 
'Get a free file number 
FNum = FreeFile 
 
'Open the file 
Open "image.dat" For Binary As #FNum 
 
'Do the first read on PartImage, buffer must be a variant 
AmountRead = PartImage.Read(buffer, chunksize) 
 
'put will not allow Variant type 
buf = buffer 
Put #FNum, , buf 
 
' Check for the Status property for polling read operation 
While PartImage.Status = ORALOB_NEED_DATA 
    AmountRead = PartImage.Read(buffer, chunksize) 
    buf = buffer 
    Put #FNum, , buf 
Wend 
 
Close FNum 

Example: Single-Piece Read of a LOB

Dim OraSession As OraSession 
Dim OraDatabase As OraDatabase 
Dim PartDesc As OraClob 
Dim AmountRead As Long 
Dim buffer As Variant 
Dim buf As String 
 
'Create the OraSession Object. 
Set OraSession = CreateObject("OracleInProcServer.XOraSession") 
 
'Create the OraDatabase Object. 
Set OraDatabase = OraSession.OpenDatabase("ExampleDb", "scott/tiger", 0&)
 
'Add PartDesc as an Output parameter and set its initial value. 
OraDatabase.Parameters.Add "PartDesc", Null, ORAPARM_OUTPUT 
OraDatabase.Parameters("PartDesc").ServerType = ORATYPE_CLOB 
 
'Execute the statement returning 'PartDesc' 
OraDatabase.ExecuteSQL ("BEGIN select part_desc into :PARTDESC from" & _ 
             "part where part_id = 1 for update NOWAIT; END;") 
 
'Get 'PartDesc' from Parameters collection 
Set PartDesc = OraDatabase.Parameters("PartDesc").Value 
 
'Get a free file number 
FNum = FreeFile 
 
'Open the file. 
 
Open "Desc.Dat" For Binary As #FNum 
 
'Read entire CLOB value, buffer must be a Variant 
AmountRead = PartDesc.Read(buffer) 
 
'put will not allow Variant type 
buf = buffer 
Put #FNum, , buf 
 
Close FNum