Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Help!!! IT'S THE BLOB...
Here is one way to do it in VB...
'This is Important! Option Base must = 1 for this example to work
'otherwise the data retreived will be incorrect
Option Base 1
Private Sub Command1_Click()
' Create Table script
' create table testlraw ( c1 number primary key, name varchar2(100),
c2 number, c3 long raw);
' Max ChunkSize is < 32k
Const ChunkSize = 4096
Dim RawData() As Byte
Dim RawLength As Long
Dim Offset As Long
Dim oev As rdoEnvironment
Dim odb As rdoConnection
Dim ody As rdoResultset
' Establsh a connection
Set oev = rdoEnvironments(0)
oev.CursorDriver = rdUseOdbc
Set odb = oev.OpenConnection("", rdDriverNoPrompt, False,
"DSN=V803-TEST;UID=SCOTT;PWD=TIGER;")
'This sql could be modifed to include a where condition, or you could
use the
'find/move methods of the ResultSet to position yourself on the
correct row for
'update...
Set ody = odb.OpenResultset("select name, c1, c2, c3 from testlraw for
update", rdOpenDynamic, rdConcurRowVer)
' Read the target file from disk
Open "D:\STAGE\TEST.ZIP" For Binary Access Read As #1
If ody.EOF = True Then
ody.AddNew
Else
ody.Edit
End If
' Establsh the length of the raw data and the number of chunks
required
RawLength = LOF(1)
Offset = 1
Do
If Offset + ChunkSize <= RawLength Then
ReDim RawData(ChunkSize)
Else
ReDim RawData(RawLength - Offset + 1)
End If
Get #1, Offset, RawData()
ody!c3.AppendChunk RawData()
Offset = Offset + ChunkSize
Loop While Offset < RawLength
Close #1
ody!c2.Value = RawLength ody!Name.Value = "TEST" ody!c1.Value = 1
ody.Close
Set ody = odb.OpenResultset("select name, c1, c2, c3 from testlraw", rdOpenDynamic, rdConcurRowVer)
' Write the returned file out to disk
Open "D:\STAGE\f.zip" For Binary Access Write As #1
' Establsh the length of the raw data
' Note: RawLength = ody("c3").ColumnSize will always return -1 with
Oracle
' However, this may be valid on other vendor DBs -or- you can
' make use of the generic code that handles '-1' returns below
' to determine the column size on the fly
'RawLength = ody("c3").ColumnSize
' Note: It is expected that you store the length of the target column
' on upload both to speed up this process and to provide a checksum
RawLength = ody("c2").Value
Dim RawTemp As Variant
Offset = 1
If RawLength = -1 Then
Do
RawTemp = ody!c3.GetChunk(ChunkSize)
RawData() = RawTemp
Put #1, Offset, RawData()
Offset = Offset + LenB(RawTemp)
Loop While LenB(RawTemp) = ChunkSize
Else
Do
RawData() = ody!c3.GetChunk(ChunkSize)
Put #1, Offset, RawData()
Offset = Offset + ChunkSize
Loop While Offset < RawLength
End If
Close #1
ody.Close
odb.Close
MsgBox "Done"
End Sub Received on Fri May 29 1998 - 00:00:00 CDT
![]() |
![]() |