Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle database insert of a blob image by a C and VB programing methodes.
Here is an example, but this will not work on an Oracle 8 BLOB column
type. OO4O does not yet deal with anything Oracle 8 specific. Use a
LONG RAW column instead.
' Max ChunkSize is < 32k
Const ChunkSize = 4095
Dim FetchSize As Long
Dim RawData() As Byte
Dim RawLength As Long
Dim Offset As Long
Dim osess As OraSession
Dim odata As OraDatabase
Dim odyna As OraDynaset
' Establsh a connection
Set osess = CreateObject("OracleInProcServer.XOraSession") Set odata = osess.CreateDatabase("TNS:ExampleDb", "scott/tiger", 0&) Set odyna = odata.CreateDynaset("select * from testlraw", 0&)
' Read the target file from disk
Open "D:\STAGE\POSTIE.ZIP" For Binary Access Read As #1
odyna.Edit
' 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)
End If
Get #1, Offset, RawData()
odyna!c3.AppendChunk RawData()
Offset = Offset + ChunkSize + 1
Loop While Offset < RawLength
Close #1
odyna!c2.Value = RawLength
odyna.Update
odyna.Refresh
' Write the returned file out to disk
Open "D:\STAGE\OUT.EXE" For Binary Access Write As #1
' 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 = odyna("c2").Value
ReDim RawData(ChunkSize)
Offset = 1
If RawLength = -1 Then
Do
FetchSize = odyna!c3.DbGetChunkByte(RawData(0), Offset - 1,
ChunkSize)
Put #1, Offset, RawData()
Offset = Offset + FetchSize
Loop While FetchSize = ChunkSize
Else
Do
FetchSize = odyna!c3.DbGetChunkByte(RawData(0), Offset - 1,
ChunkSize)
If FetchSize < ChunkSize Then
ReDim RawData(FetchSize - 1) FetchSize = odyna!c3.DbGetChunkByte(RawData(0), Offset - 1,FetchSize - 1)
End If
Put #1, Offset, RawData()
Offset = Offset + FetchSize
Loop While Offset < RawLength
End If
Close #1
odyna.Close
odata.Close
MsgBox "Done"
Received on Mon Jun 08 1998 - 08:52:56 CDT
![]() |
![]() |