Re: ADO and Informix Blob
Posted in 1998
This problem also occurs with RDO using InterSolv's ODBC driver. You need to set the ROWSET size to 1 instead of the default value of 100 before opening the resultset. There are no problems reading and writing BLOB columns to Informix as long as the rowset size is set to 1. Example code for RDO: '*** READ A BLOB COLUMN FROM TABLE '*** '*** Read_Blob("log.rep_txt","log_id=123","C:\\temp\\blob0000001.txt") ' '*** Original version Sub Read_Blob(TabColNam As String, WhereStr As String, Target_Path As String) Dim TabNam As String 'Table Containing Blob Column Dim ColNam As String 'Column (Field) Containing Blob Dim Sql As String 'Select Statement Dim Rs As rdoResultset 'Resultset Object Pointer Dim Qry As New rdoQuery Dim Col As rdoColumn 'RDO Column Object Pointer Const Bufsiz = 500000 'Size of Blob Chunks to read Dim buf() As Byte 'Buffer for storing a blob chunk Dim Blobsize As Long 'Size of Blob/Image in bytes Dim Chunks As Long 'No of FULL blob chunks to read Dim Remainder As Long 'Remaining (Odd) blob bytes to read Dim i As Integer i = InStr(TabColNam, ".") 'Split "table.column" If i = 0 Then RaiseError 901, "TABLE.COLUMN (" & TabColNam & ") Invalid Syntax" End If TabNam = Left(TabColNam, i - 1) 'Blob Table ColNam = Right(TabColNam, Len(TabColNam) - i) 'Blob Column Sql = "SELECT " & ColNam & " FROM " & TabNam & " WHERE " & WhereStr With Qry 'rdoQuery Object Set .ActiveConnection = Con 'Use Global Connection .Sql = Sql .LockType = rdConcurReadOnly 'Needed for Informix Blobs .RowsetSize = 1 'Needed for Informix Blobs .CursorType = rdUseServer 'Cursor Library SERVER SIDE End With On Error Resume Next '*** SELECT Single Blob Column From Database If DbCon.MsAccess Then '*** SQL Server or MS-Access Set Rs = Qry.OpenResultset(rdOpenForwardOnly) ''Set Rs = Con.OpenResultset(Sql, rdOpenKeyset, rdConcurReadOnly) Else '*** Informix Set Rs = Qry.OpenResultset(rdOpenForwardOnly) ''Set Rs = Con.OpenResultset(Sql, rdOpenForwardOnly, rdConcurReadOnly) End If If Err Then On Error GoTo 0 RaiseError 902, "Read_Blob() - Failed OpenResultset() Err=" & Str(Err) End If On Error GoTo 0 If Rs.EOF Then RaiseError 903, "Read_Blob() - Blob Row Not Found" End If Set Col = Rs(0) 'rdoColumn(0) On Error Resume Next Kill Target_Path 'Ensure Target does not exist On Error GoTo 0 Open Target_Path For Binary Access Write As #1 'Temp Disk File for Blob Blobsize = Col.ColumnSize 'Blob Size in bytes Chunks = Blobsize \\ Bufsiz 'No of blob Chunks to read Remainder = Blobsize Mod Bufsiz 'Remaining Blob bytes to read '*** Get Remainder 1st ReDim buf(Remainder) buf() = Col.GetChunk(Remainder) 'Get Initial Blob Chunk Put #1, , buf() 'Write to Disk File '*** Get Chunks Now ReDim buf(Bufsiz) For i = 1 To Chunks buf() = Col.GetChunk(Bufsiz) 'Get Subsequent Blob Chunk Put #1, , buf() 'Write to Disk File Next i Close #1 'Close Disk File Rs.Close 'Close Resultset Set Qry = Nothing End Sub