Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Appending from a text file
Message
De
19/01/2015 06:51:04
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01613872
Message ID:
01613873
Vues:
49
>I can import data from a text file sdf and it creates a table with 2 text fields followed by a memo field - so far so good
>
>But when I try to append more data into this file the memo field is blank - the other 2 fields have the correct data - the following is my code
>
>SELECT consiga
>append FROM d:\consman\back\consiga.txt TYPE sdf
>
>How can I correct this?

You can't... SDF format means fixed length. Memo fields and fixed length can't exist in the same file.

IOW, memo fields inside a text file is pretty much nonsense, as a memo field IS a text file inside a field, so this may become recursive really fast (aside: anyone who says "inception" will have to watch the movie ten times until he (or they, but then all of them) learn(s) the meaning of terms). There have to be separators, so you would know where each field begins and ends, plus the end-of-record marker. The trouble is that the end-of-record is usually a cr+lf, but then the memo may contain the same. The field delimiter is usually a comma, but memo may contains commas. The other famous delimiter is tab character, again, memo may contain tabs. Character fields (including memos) may be surrounded with quotes, but then a memo may contain quotes. In some languages, a delimiter inside a string should be doubled, so if a memo contains ", those should be turned into "" before writing out into the textfile... but that's an internal agreement between the exporter and importer, and not a general rule.

Look, I write imports from text files and spreadsheets for breakfast, and I have a whole library of handy tricks for whichever finicky and capricious exporter may be out there, and each time I have to mix and match whatever works for a particular situation. And mind you, for those which aren't one-time imports (aka conversions from legacy data) it's actually worse, as they all change the format sooner or later, and then it's always something to be fixed again and again. Even when you get a sample in advance, the sample is not representative, as the person preparing the export knows pretty much nothing of what I listed in the previous paragraph, to them it's "all exported into a textfile, what else do you want?". They tend to think it's a kind of magic which pours those textfiles into a database. Well, it is, but as one who has to write that magic, I can say I'm not a happy camper...

SET RANT OFF

So your best bet is to take a hex editor and look into the structure of your file. Spot the delimiters, spot the separators, see whether you can spot the beginning and the end of the embedded memo... and then start writing code. Filetostr(), alines() (study ALL parameters of it), strextract(), getwordnum(), getwordcount() are your new best friends.

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