ヘッダーをスキップ
Oracle® Objects for OLE開発者ガイド
11gリリース2 (11.2) for Microsoft Windows
B58887-04
  目次へ移動
目次
索引へ移動
索引

前
 
次
 

GetChunkByteExメソッド

説明

LONGまたはLONG RAW型のフィールドからデータを読み込み、Variantに格納し、読み込んだデータのサイズを戻します。

使用方法

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

引数

このメソッドの引数は、次のとおりです。

引数 説明
ByteArray データを格納するVariant型のバイト配列の名前。
offset データのコピー前にスキップするフィールド内のバイト数。
numbytes コピーするバイト数。

備考

可能な場合、GetChunkByteExメソッドは、ローカル・キャッシュから指定されたバイト数を取り出します。ただし、一部のデータは、リソース節約のために、ローカルに格納されない場合があります。この場合、GetChunkByteExメソッドは、必要に応じてデータベースから必要なデータを要求します。この処理の一部として、ダイナセット内のすべてのフィールド(LONGまたはLONG RAW型のフィールドを除く)が取り出されて、一貫性検査のためにキャッシュされている値と比較されます。元の部分データのフェッチ後に変更があった場合、GetChunkByteExは操作を中止し、エラーを戻します。

GetChunkByteExメソッドの最初のパラメータは、バイト配列の最初の要素を指定するGetChunkByteメソッドとは異なり、Variantであるため、ASP/IIS環境ではGetChunkByteExメソッドのみ使用可能です。

LONGまたはLONG RAW型のフィールドが65280バイト未満の場合は、GetChunkByteExメソッドを使用せずにValueプロパティを使用すると、データを速く取り出すことができます。

「LONG RAWからLOBまたはBFILEへの移行」を参照してください。

GetChunkByteExメソッドを使用してLONG RAW型の列を取り出す例

この例では、GetChunkByteExメソッドを使用してデータベース内のLONG RAW型の列を取り出し、ファイルとして保存する方法を示します。この例では、type_longrawという列を含んだ表を示すOraDynasetという有効なダイナセットが存在していると想定しています。このコードをコピーして、フォームの定義セクションに貼り付けてください。このプロシージャは、有効なファイル名を使用してコールしてください。

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

Active Server Pages(ASP)でGetChunkByteExメソッドを使用する例

'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 
%>