Skip Headers
Oracle® Objects for OLE Developer's Guide
11g Release 2 (11.2) for Microsoft Windows

Part Number E17727-03
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

GetChunkByteEx Method

Applies To

OraField Object

Description

Reads the data from a LONG or LONG RAW field into a Variant and returns the amount of data read.

Usage

amount_read = orafield.GetChunkByteEx(ByteArray, offset, numbytes) 

Arguments

The arguments for the method are:

Arguments Description
ByteArray The name of the Variant ByteArray to hold the data.
offset The number of bytes in the field to skip before copying data.
numbytes The number of bytes to copy.

Remarks

When possible, the GetChunkByteEx method retrieves the specified bytes from the local cache. However, to conserve resources, some of the data might not be stored locally. In these cases, the GetChunkByteEx method requests the necessary data from the database as required. As part of this process, data from all fields (except the LONG or LONG RAW field) in the dynaset are retrieved and compared to the cached values for consistency. If any changes have occurred since the fetch of the original partial data, then the GetChunkByteEx method aborts the operation with an error.

Because the GetChunkByteEx method takes in a Variant as the first parameter, instead of the first element of the ByteArray as in the GetChunkByte method, only the GetChunkByteEx method can be used within an ASP/IIS environment.

If a LONG or LONG RAW field is less than 65280 bytes in size, it is quicker to retrieve the data using the Value property than using the GetChunkByteEx method.

See "Migration from LONG RAW to LOB or BFILE".

Examples

Using the GetChunkByteEx Method to Retrieve a LONG RAW Example

This example demonstrates the use of the GetChunkByteEx method to retrieve a LONG RAW column of a database and save it as a file. This example expects a valid dynaset named OraDynaset representing a table with a column named type_longraw. Copy and paste this code into the definition section of a form. Call this procedure with a valid file name.

Sub GetChunkByteExExample (FName As String) 
'Declare various variables 
Dim bytesread As Integer, ChunkSize As Long ,
 
bytearr() as byte 
Dim I As Integer, FNum As Integer, CurChunk 
'Set the size of each chunk 
ChunkSize = 10240 
  
frmChunk.MousePointer = HOURGLASS 
'Get a free file number 
FNum = FreeFile 
'Open the file 
Open FName For Binary As #FNum 
I = 0 
'Loop through all of the chunks 
'Oracle does not return the size of columns > 64KB. 
'We should loop until the length of our block is 
'less than we asked for. 
Do 
  bytesread = OraDynaset.Fields("type_longraw").GetChunkByteEx(CurChunk,_
              I * ChunkSize, ChunkSize) 
'redim byte array 
redim bytearr(bytesread - 1) 
bytearr = CurChunk 
Put #FNum, , bytearr 'Write chunk to file. 
I = I + 1 
Loop Until bytesread < ChunkSize 
'Close the file. 
Close FNum 
frmChunk.MousePointer = DEFAULT 
End Sub

Using the GetChunkByteEx Method with Active Server Pages (ASP) Example

'This example is for use with ASP (Active Server Pages) 
<%@ LANGUAGE = VBScript %> 
<%Response.ContentType = "image/JPEG"%> 
<% 
Dim OraDatabase, Oradynaset 
Dim Chunksize, BytesRead, CurChunkEx 
'This assumes a pool of database connections have been created in the global.asa 
Set OraDatabase = OraSession.getDatabaseFromPool(10) 
'This assumes a table called "art_gallery" and 
'displays JPEG images stored in the table 
Set OraDynaset = OraDatabase.CreateDynaset("select art from art_gallery " & _
              "where artist = 'Picasso'", 0) 
 
BytesRead = 0 
'Reading in 32K chunks 
ChunkSize= 32768 
Do 
  BytesRead = OraDynaset.Fields("picture").GetChunkByteEx(CurChunkEx, _
                                 i * ChunkSize, ChunkSize) 
  if BytesRead > 0 then 
     Response.BinaryWrite CurChunkEx 
   end if 
Loop Until BytesRead < ChunkSize 
'Cleanup, remove all local references 
Set OraDynaset = Nothing 
Set Oradatabase = Nothing 
%>