使用方法
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 。次の値を指定できます。
|
[out ] amount_written |
書込み量を表す整数。OraCLOB オブジェクトの場合は文字数、OraBLOB またはOraBFILE オブジェクトの場合はバイト数を示します。
|
備考
Write
メソッドのコール前に、行レベルまたはオブジェクト・レベルでロックを取得する必要があります。このメソッドは、Offset
プロパティで指定されたオフセットからBLOB
データまたはCLOB
データを書き込みます。複数ピースの書込み操作の場合は、PollingAmount
プロパティを書込みデータ長の合計数の値に設定でき、Status
プロパティをチェックして各ピースの操作が正常に実行されたことを確認する必要があります。合計数が不明な場合、PollingAmount
プロパティを0
に設定でき、ピースの型がOraLob_piece
でない場合は、ポーリングが引き続き発生します。
最後のピースについては、ピース引数をORALOB_LAST_PIECE
に設定します。ポーリングの量をバイト数または文字数で書き込む必要があります。PollingAmount
プロパティがゼロ以外の場合、Write
操作を早期に終了することはできません。
OraLOBのPollingamount
が0
で、OraLOBのWrite
のピースの型がORALOB_ONE_PIECE
でない場合は、ポーリングが引き続き発生します。ORALOB_LAST_PIECE
がWrite
メソッドへのコールの引数として送信されると、ポーリングが完了します。これは、OraCLOB.Write
メソッドを可変長キャラクタ・セットでコールする際、文字の合計数を事前にカウントすると負荷がかかる場合に便利です。
注意: Write やCopyFromFile など、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