Sub Click(Source As Button)
Dim ADOConnection As Variant, ADOCmd As Variant , RecordSet As Variant, ADOStream As Variant, ADOField As Variant
Dim RecordsCnt As Long, intLoop As Long, FileLength As Long, NumBlocks As Long, LeftOver As Long
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const Blocksize = 4096
Set ADOConnection = CreateObject( "ADODB.Connection" )
ADOConnection.Open "Provider=Ifxoledbc;Data Source=clipper@ol_asu;User ID=lotus-user;Password=09032010;Persist Security Info=true;"
If ADOConnection.State = 0 Then
Exit Sub
End If
Set RecordSet = CreateObject( "ADODB.Recordset" )
RecordSet.Open "foto", ADOConnection
If RecordSet.State = 0 Then
Print "==================== RecordSet.State = 0 ===================="
Goto l_finish
End If
If Not( ( RecordSet.BOF <> True ) Or ( RecordSet.EOF <> True ) ) Then
Goto l_finish
End If
Set ADOStream = CreateObject( "ADODB.Stream" )
ADOStream.Type = adTypeBinary
RecordSet.MoveFirst
Do
RecordsCnt = RecordsCnt + 1
Call ADOStream.Open
Set ADOField = RecordSet.Fields( "foto" )
FileLength = ADOField.ActualSize
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
If LeftOver <> 0 Then
ADOStream.Write ADOField.getchunk( LeftOver ) 'This gathers the remainder portion of the stream first, you could do it last if you want
End If
For intLoop = 1 To NumBlocks 'Now loop through the majority of the stream
ADOStream.Write ADOField.getchunk( BlockSize )
Next
Call ADOStream.SaveToFile( "C:\IBM\Photos\" + Cstr( RecordSet( "lc" ).value ) + ".gif", adSaveCreateOverWrite )
Call ADOStream.Close
If ( RecordsCnt Mod 50 ) = 0 Then
Print "==================== обработано записей: " + Cstr( RecordsCnt ) + " ===================="
End If
RecordSet.MoveNext
Loop While RecordSet.EOF = False
l_finish:
RecordSet.Close
ADOConnection.Close
Exit Sub
onerr:
Call LogErrorEx( Cstr( Getthreadinfo(1) ), 1, Nothing )
Resume rez
rez:
End Sub