Exporting to Text

Beatrix Willius bwillius at gmx.de
Mon Dec 5 18:42:42 CST 2005


Hello,

I want to export a Valentina database to a tab separated text file.  
The standard Valentina export is not used, because I want to give the  
user some feedback regarding the export when the databases get a bit  
bigger.  How can I speed the below code up? From what I tried it  
seems that the loop through the records and fields and getting the  
strings takes the most time.


The variable theArchiveFolderitem is (guess what?) as non-nil  
folderitem. The variable theDatabase is a Valentina database.

dim theCursor as VCursor
   theCursor = theDatabase.SqlSelect("select * from message" ,  
kV_Server, kV_ReadWrite, kV_Random)
   theArchive = theArchiveFolderitem.CreateBinaryFile("text")

   dim FieldValue as String
   dim theLine as new StringHandleMBS
   dim FieldCount as integer = theDatabase.BaseObject 
("Message").FieldCount
   dim RecordCount as Integer = theCursor.RecordCount
   'Loop through each row and save
   for currentRecord as integer = 1 to RecordCount
     theCursor.CurrentPosition = currentRecord

     'get the values and add to line
     for currentField as integer = 1 to FieldCount
       if theCursor.Field(currentField).isNull then
         FieldValue = ""
       else
         FieldValue = theCursor.Field(currentField).GetString
       end if

       'set encoding
       FieldValue = DefineEncoding(FieldValue, Encodings.MacRoman)

       'replace return and tab
       if InStr(FieldValue, EndOfLine) > 0 then
         FieldValue = ReplaceAll(FieldValue, EndOfLine, "\return")
       end if
       if InStr(FieldValue, chr(9)) > 0 then
         FieldValue = ReplaceAll(FieldValue, chr(9), "\tab")
       end if

       'add to line
       if theLine.Len = 0 then
         theLine.Add FieldValue
       else
         theLine.Add chr(9) + FieldValue
       end if
     next

     'write in pieces of 1 MB
     if theLine.Len > 1000 * 1024 then
       theArchive.Write theLine.Copy + EndOfLine
       theLine.Delete 1, theLine.Len
     elseif currentRecord = theCursor.RecordCount then
       'write end of archive
       theArchive.Write theLine.Copy
     end if

   next

Using Valentina 1.11 RB with RB 2005.4 on Mac OS 10.4

Any ideas are appreciated.






More information about the Valentina mailing list