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

前
 
次
 

Write(OraLOB)メソッド

説明

バッファをこのオブジェクトのBLOBまたはCLOB値に書き込み、書込みデータ長の合計を戻します。

使用方法

amount_written = OraBlob.Write buffer, chunksize, piece
amount_written = OraClob.Write buffer, chunksize, piece
 

引数

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

引数 説明
in] buffer OraCLOBオブジェクトの場合は文字配列、ピースの書込み元のOraBLOBオブジェクトの場合はバイト配列。
[in] [オプション] chunksize バッファの長さを指定するためのIntegerで、OraCLOBオブジェクトの場合は文字数、OraBLOBまたはOraBFILEオブジェクトの場合はバイト数を示します。デフォルト値は、バッファの引数のサイズです。
[in] [オプション] piece バッファを書き込むピースを指定するためのInteger。次の値を指定できます。
  • ORALOB_ONE_PIECE - バッファを単一ピースで書き込みます。これがデフォルトになります。

  • ORALOB_FIRST_PIECE - バッファは、書き込まれるLOBデータの最初のピースを表します。

  • ORALOB_NEXT_PIECE - バッファは、書き込まれるLOBデータの次のピースを表します。

  • ORALOB_LAST_PIECE - バッファは、書き込まれるLOBデータの最後のピースを表します。

[out] amount_written 書込み量を表す整数。OraCLOBオブジェクトの場合は文字数、OraBLOBまたはOraBFILEオブジェクトの場合はバイト数を示します。

備考

Writeメソッドのコール前に、行レベルまたはオブジェクト・レベルでロックを取得する必要があります。このメソッドは、Offsetプロパティで指定されたオフセットからBLOBデータまたはCLOBデータを書き込みます。複数ピースの書込み操作の場合は、PollingAmountプロパティを書込みデータ長の合計数の値に設定でき、Statusプロパティをチェックして各ピースの操作が正常に実行されたことを確認する必要があります。合計数が不明な場合、PollingAmountプロパティを0に設定でき、ピースの型がOraLob_pieceでない場合は、ポーリングが引き続き発生します。

最後のピースについては、ピース引数をORALOB_LAST_PIECEに設定します。ポーリングの量をバイト数または文字数で書き込む必要があります。PollingAmountプロパティがゼロ以外の場合、Write操作を早期に終了することはできません。

OraLOBのPollingamount0で、OraLOBのWriteのピースの型がORALOB_ONE_PIECEでない場合は、ポーリングが引き続き発生します。ORALOB_LAST_PIECEWriteメソッドへのコールの引数として送信されると、ポーリングが完了します。これは、OraCLOB.Writeメソッドを可変長キャラクタ・セットでコールする際、文字の合計数を事前にカウントすると負荷がかかる場合に便利です。


注意:

WriteCopyFromFileなど、LOBのメソッドを使用したLOBの操作では、古いデータと比較して新しいデータが短い場合、LOBオブジェクトは自動的に切り捨てられません。LOBオブジェクトを新しいデータのサイズに縮小するには、Trim(OraLOB)メソッドを使用します。

「LOBデータ型の例で使用されているスキーマ・オブジェクト」の説明に従ってOraLOBスキーマ・オブジェクトをインストールしていることを確認してください。

LOBの複数ピース書込みの例

Dim OraSession As OraSession 
Dim OraDatabase As OraDatabase 
Dim OraDynaset As OraDynaset 
Dim PartDesc As OraClob 
Dim buffer As String 
Dim chunksize As Long 
Dim amount_written As Long 
 
'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&) 
Set PartDesc = OraDynaset.Fields("part_desc").Value 
chunksize = 32000 
 
'Re adjust the buffer size 
buffer = String$(chunksize, 32) 
FNum = FreeFile 
 
'Open the file. 
Open "partdesc.dat" For Binary As #FNum 
 
'set the offset and PollingAmount properties for piece wise
'Write operation 
PartDesc.offset = 1 
PartDesc.PollingAmount = LOF(FNum) 
remainder = LOF(FNum) 
 
'Lock the row for write operation 
OraDynaset.Edit 
Get #FNum, , buffer 
 
'Do first write operation 
amount_written = PartDesc.Write(buffer, chunksize, ORALOB_FIRST_PIECE)  
 
While PartDesc.Status = ORALOB_NEED_DATA 
  remainder = remainder - chunksize 
  If remainder < chunksize Then 
    piecetype = ORALOB_LAST_PIECE 
    chunksize = remainder 
   Else 
    piecetype = ORALOB_NEXT_PIECE 
  End If 
  Get #FNum, , buffer 
 
  amount_written = PartDesc.Write(buffer, chunksize, piecetype) 
Wend 
 
Close FNum 
 
'call Update method to commit the transaction 
OraDynaset.Update 

LOBの単一ピース書込みの例

Dim OraSession As OraSession 
Dim OraDatabase As OraDatabase 
Dim PartImage As OraBlob 
Dim buffer() As Byte 
 
'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 "PartImage", Null, ORAPARM_OUTPUT 
OraDatabase.Parameters("PartImage").ServerType = ORATYPE_BLOB 
 
'Begin the transaction 
OraSession.BeginTrans 
 
'Execute the statement returning 'PartDesc' 
OraDatabase.ExecuteSQL ("BEGIN select part_image into :PARTIMAGE" & _ 
            "from part where part_id = 1 for update NOWAIT; END;") 
 
'Get 'PartDesc' from Parameters collection 
Set PartImage = OraDatabase.Parameters("PartImage").Value 
 
'Get a free file number 
FNum = FreeFile 
 
'Open the file. 
Open "PartImage.Dat" For Binary As #FNum 
 
'Re adjust the buffer size to hold entire file data 
ReDim buffer(LOF(FNum)) 
Get #FNum, , buffer 
 
'Do one write operation 
amount_written = PartImage.Write(buffer) 
 
Close FNum 
MsgBox "Amount written to the LOB data is " & amount_written 
 
'Ends the transaction 
OraSession.CommitTrans