Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Import text file - more than 256 fields
Message
 
 
To
28/03/2004 21:15:21
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00890295
Message ID:
00890321
Views:
21
Peter,

Here's one cut that should be somewhat faster:
SELECT FD && hoist out of the loop there is no need to keep selecting the work area
          && for every line of the file

DO WHILE ! FEOF( nCDataHandle ) && can get rid of the seperate IF by testing this here
   DataString = FGETS(nCDataHandle,5000)
   m.Start = 1
   SCAN
      m.FieldNum = FD.Field_Name
      FieldData = SUBSTR(DataString,m.Start,FD.Field_Len)
      store IIF(FD.Field_Type = 'N',VAL(m.FieldData),m.FieldData) to (FieldNum)
      m.Start = m.Start + FD.Field_Len
   ENDSCAN

   INSERT INTO (OutputName) FROM MEMVAR

enddo
The STORE command can use a name expression as it's destination and you avoid the cost of macro expansion.

You could also use an array instead:
dimension laData( reccount( "fd" ) )
scan
   FieldData = SUBSTR(DataString,m.Start,FD.Field_Len)
   laData[recno( "fd" )] = iif(FD.Field_Type = 'N',VAL(m.FieldData),m.FieldData)
   m.Start = m.Start + FD.Field_Len
endscan
insert into (OutputName) from array laData
I don't really see what in there is dealing with more than 256 columns. Since this appears to be an SDF so something like this might work well for you:
fhOut1 = fopen( "temp1.txt", 1 )
fhout2 = fopen( "temp2.txt", 1 )
do while ! feof( fhIn )
   lcAllData = fgets( fhIn, 5000 )
   fputs( fhOut1, substr( lcAllData, 1, lnSlplitPoint ) )
   fputs( fhOut2, substr( lcAllData, lnSplitPoint + 1 ) )
enddo

fclose && each handle
select Table1
append from temp1.txt type sdf
select Table2
append from temp2.txt type sdf
Actually you don't have to split off the first set of bytes from each row because the first append from could use the original input file and it'll ignore the part of the line that doesn't fit in Table1.

>I assumed that VFP didn't use file buffering for low-level reads. I did a test without the parsing and it was a lot faster. So I guess it must indeed be the parsing code that is so slow. This is the code:
>
>FD is a table that contains the field definitions for the input file. It is used to create the table that will contain the data (using the CREATE FROM command) and is also used to parse the text.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform