Problem with SAVECSV

epsharp

Member
Licensed User
Longtime User
Using a Windows Text Editor, this is almost impossible to find & I spent an inordinate amount of time debugging this:

The instruction Table1.SaveCSV ("fName.csv", "," ,False) places Chr(239) Chr(187) Chr(191) in the first three (3) position of the first field in the first record!

Can someone please tell me why and is there a way to stop it?


Regards,

Ed sharp
 

agraham

Expert
Licensed User
Longtime User
It is a BOM (Byte Order Mark) that signifies that the data in the file is encoded as UTF8 characters. You can't stop it, it is what the .NET StreamWriter class does when encoding UTF8 data. Ideally you need a text editor that is UTF8 aware. Look at UTF-8 - Wikipedia, the free encyclopedia
 

epsharp

Member
Licensed User
Longtime User
Explanation Appreciated... but still a bug!

Dear Agraham,

Thanks for the explanation and if the instruction was SaveTXT I would say your reply was all that was needed.

But if you try this:

LOAD DATA INFILE '/TEST.csv' INTO TABLE test
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r'
(COL1)

...with any database that supports the LOAD INFILE of a CSV file you get a corrupted database field.

There is a much broader concept of files with the type of CSV. While the debate of CSV standards still persist, it is usually accepted that fields are separated by commas and text is enclosed in quotes. CSV also implies portability in that programs supporting these files are expecting numbers and strings. Try double clicking on the SaveCSV file and (if you have it) Microsoft Excel pops open and low and behold, the first field is corrupted.

The SaveCSV has the commas, but not the quotes (these days quotes are mostly optional, but not to older programs) and the first record gets a BOM!

One would hope that a future release would have the option (as does B4PPC FileOpen) to specify ASCII encoding and optional quotes.

If anyone else needs ASCII CSV Table output, the attached works just fine.


Regards

Ed Sharp
 

Attachments

  • SaveTable.sbp
    982 bytes · Views: 227

agraham

Expert
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…