VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



ADO Upload and Retrieve ORACLE BLOB

by Herman Ibrahim (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

To upload and retrieve ORACLE BLOB File using ADO Recordset.
Never try with other than ORACLE database, but i think i can ...

Inputs
File Name BLOB / LongRaw Field Name ADO Blob RecordSet
Assumes
I get this function somewhere from microsoft.com Then the function is rewritten to make sure that it is easy to use and reuse...
Code Returns
Boolean

Rate ADO Upload and Retrieve ORACLE BLOB

Function AddLongRaw(ByVal strFileName As String, ByRef objRecSet As ADODB.Recordset, ByVal strFieldName As String) As Boolean
 'How to call AddLongRaw function :
 'dim bool as boolean
 'dim objRecSet as new adodb.recordset
 'dim strFieldeName as string
 'strFieldName = objRecSet.Fields("YOUR_BLOB_FILE").Name
 'bool = AddLongRaw(strSourceName, objRecSet, strFieldName)
 
 'if bool then
  'Successfully upload the BLOB file into database
 'else
  'Failed to upload the BLOB file into database
 'End If
 
 AddLongRaw = False
 Dim ByteData() As Byte 'Byte array for Blob data.
 Dim SourceFile As Integer
 Dim FileLength As Long
 Dim Numblocks As Integer
 Dim LeftOver As Long
 Dim i As Integer
 Const BlockSize = 10000 'This size can be experimented with for
 SourceFile = FreeFile
 Open strFileName For Binary Access Read As SourceFile
 FileLength = LOF(SourceFile)  ' Get the length of the file.
 
 'Debug.Print "Filelength is " & FileLength
 
 If FileLength = 0 Then
  Close SourceFile
  AddLongRaw = False
  Exit Function
 Else
  Numblocks = FileLength / BlockSize
  LeftOver = FileLength Mod BlockSize
  ReDim ByteData(LeftOver)
  Get SourceFile, , ByteData()
  objRecSet.Fields(strFieldName).AppendChunk ByteData()
  ReDim ByteData(BlockSize)
   For i = 1 To Numblocks
   Get SourceFile, , ByteData()
   objRecSet.Fields(strFieldName).AppendChunk ByteData()
   Next i
   AddLongRaw = True
   Close SourceFile
 End If
End Function
Function GetLongRaw(strFileName As String, objRecSet As ADODB.Recordset, strBLOBFieldName As String) As Boolean
 GetLongRaw = False
 Dim ByteData() As Byte 'Byte array for file.
 Dim DestFileNum As Integer
 Dim DiskFile As String
 Dim FileLength As Long
 Dim Numblocks As Integer
 Const BlockSize = 10000
 Dim LeftOver As Long
 Dim i As Integer
 
 FileLength = objRecSet.Fields(strBLOBFieldName).ActualSize
 
 ' Remove any existing destination file.
 DiskFile = strFileName
 If Len(Dir$(DiskFile)) > 0 Then
  Kill DiskFile
 End If
 
 DestFileNum = FreeFile
 Open DiskFile For Binary As DestFileNum
 Numblocks = FileLength / BlockSize
 LeftOver = FileLength Mod BlockSize
 
 ByteData() = objRecSet.Fields(strBLOBFieldName).GetChunk(LeftOver)
 Put DestFileNum, , ByteData()
 For i = 1 To Numblocks
  ByteData() = objRecSet.Fields(strBLOBFieldName).GetChunk(BlockSize)
  Put DestFileNum, , ByteData()
 Next i
 Close DestFileNum
 GetLongRaw = True
'============
'The object file is now located at strFileName
'============
End Function

Download this snippet    Add to My Saved Code

ADO Upload and Retrieve ORACLE BLOB Comments

No comments have been posted about ADO Upload and Retrieve ORACLE BLOB. Why not be the first to post a comment about ADO Upload and Retrieve ORACLE BLOB.

Post your comment

Subject:
Message:
0/1000 characters