Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to remove ascii(160) characters
Message
De
18/11/2012 12:02:37
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01557507
Message ID:
01557549
Vues:
45
>At the moment I am engaged in a small project (getting less small all the time) which has me closer to the nitty gritty of string functions and LLFF than I have been in years. My task is to reverse engineer an industry standard transaction file format back into either SQL Server or FoxPro tables. The X factor is that these comma delimited files consist of heterogeneous record types. IOW record type 1 has this field format, record type 2 has this different format, and so on. The number of fields and types vary by record type. (That whirring noise you hear is Dr. Codd turning over in his grave). I haven't quite given up hope of a simple approach but so far have not found any better than dealing with the input file line by line, byte by byte. It is further complicated by records in the database being comprised of fields from different record types in the CSV file. So it's turning out to be a good deal more complicated than APPEND FROM. That's OK. It's good exercise.

Not uncommon, and not too hard, unless the delimiters can be found inside fields (when the actual fun begins).

My approach for this is to alines(a, filetostr("the.csv")) the whole file into an array, then go through the array one line at a time. Split each line into yet another array (this time holding string representation of the values) and then process it.

In your case the processing will have to branch into several cursors (one per record type), but that's about the only thing different - instead of importing from several files, each into its own cursor, you import all the cursors from the same file. In meta code...
nRows=alines(a, filetostr("the.csv"))
for i=1 to nRows
   nCols=aLines(aR, a[i])
   do case
      case aR[1]=1
* record type 1
         select cursorType1
         scatter name o blank
         o.field1=aR[2]
         o.field2=val(aR[3])
...
...
        insert into cursorType1 from name o
      case aR[1]=2
* same story for cursorType2
...
  endcase
endfor
Yes, this means you manually assign each column of a particular row type to a field in a corresponding table, but hey, it's still less time than what you'd waste looking for the magic bullet of the "AI replacement for the append from... delimited". Specially if there are some quirks in there.

OTOH, the magical bullet may be to have those three or four cursors, and that each has a, say, rectype field in the position where the record type in csv is. Then
select cursorType1
append from my.csv type csv for rectype=1
select cursorType2
append from my.csv type csv for rectype=2
* etc
But that would be too easy, and we know we aren't that lucky, ever. There must be some quirk that will get a few fields hosed if you do a straight append like that. Doesn't hurt to try, though.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform