Advertisement
1_2002 Databases/ Data Access/ DAO/ ADO #105828

ADO Upload and Retrieve ORACLE BLOB

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

AI

Résumé par IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Code source
original-source
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

Commentaires originaux (3)
Récupéré via Wayback Machine