Solved

Insert or Update and long raw datatype

Posted on 1998-11-04
1
431 Views
Last Modified: 2013-12-25
I need a source code of a Visual Basic program that's insert or update a row with one long raw datatype (for gif or jpeg images).

Client:
-------
-> Visual Basic 4.0 E.E.
-> NT 4.0
-> Driver ODBC (Oracle 73 2.5)

Server:
-------
-> Oracle 7.3.3.4 AIX
0
Comment
Question by:arapahoe
1 Comment
 
LVL 1

Accepted Solution

by:
CarlosJac earned 200 total points
ID: 1497417
If You are using DAO  to access to database, try this code

Sub GetFileFromDB(BinaryField As Field, szFileName As String)
   ' *** Will retrieve an entire Binary field and write it to disk ***

   Dim NumBlocks    As Long
   Dim TotalSize    As Long
   Dim RemBlocks    As Integer
   Dim CurSize      As Integer
   Dim nBlockSize   As Long
   Dim nI           As Integer
   Dim nFile        As Integer
   Dim CurChunk     As String

   If IsNull(BinaryField) Then Exit Sub

   nBlockSize = 32000    ' Set size of chunk.

   ' *** Get field size.
   TotalSize = BinaryField.FieldSize()
   NumBlocks = TotalSize \ nBlockSize   ' Set number of chunks.

   ' *** Set number of remaining bytes.
   RemBlocks = TotalSize Mod nBlockSize

   ' *** Set starting size of chunk.
   CurSize = nBlockSize
   nFile = FreeFile ' Get free file number.

   Open szFileName For Binary As #nFile  ' Open the file.
   For nI = 0 To NumBlocks
      If nI = NumBlocks Then CurSize = RemBlocks
      CurChunk = BinaryField.GetChunk(nI * nBlockSize, CurSize)
      Put #nFile, , CurChunk   ' Write chunk to file.
   Next
   Close nFile

End Sub

Function SaveFileToDB(sSource As String, BynaryField As Field) As Integer
   ' *** Will save a file to a Binary field

   Dim nNumBlocks       As Integer
   Dim nFile            As Integer
   Dim nI               As Integer
   Dim nFileLen         As Long
   Dim nLeftOver        As Long
   Dim sFileData        As String
   Dim Retval           As Variant
   Dim nBlockSize       As Long

   On Error GoTo Error_SaveFileToDB

   nBlockSize = 32000    ' Set size of chunk.

   ' *** Open the sSource file.
   nFile = FreeFile
   Open sSource For Binary Access Read As nFile

   ' *** Get the length of the file.
   nFileLen = LOF(nFile)
   If nFileLen = 0 Then
      SaveFileToDB = 0
      Exit Function
   End If

   ' *** Calculate the number of blocks to read and nLeftOver bytes.
   nNumBlocks = nFileLen \ nBlockSize
   nLeftOver = nFileLen Mod nBlockSize

   ' *** Read the nLeftOver data, writing it to the table.
   sFileData = String$(nLeftOver, 32)
   Get nFile, , sFileData
   BynaryField.AppendChunk (sFileData)

   ' *** Read the remaining blocks of data, writing them to the table.
   sFileData = String$(nBlockSize, Chr$(32))
   For nI = 1 To nNumBlocks
      Get nFile, , sFileData
      BynaryField.AppendChunk (sFileData)
   Next
   Close #nFile
   SaveFileToDB = nFileLen

   SaveFileToDB = 0

   Exit Function

Error_SaveFileToDB:
   SaveFileToDB = -Err
   Exit Function
   
End Function


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now