Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle database insert of a blob image by a C and VB programing methodes.

Re: Oracle database insert of a blob image by a C and VB programing methodes.

From: Mark Tomlinson <marktoml_at_gdi.net>
Date: Mon, 08 Jun 1998 13:41:12 GMT
Message-ID: <357be9a9.319627059@newshost.us.oracle.com>


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.



' Create Table script
' create table testlraw (c1 number primary key, c2 number, c3 long
raw);
' insert into testlraw values (1,1,hextoraw('FF'));

' 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:41:12 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US