Run an external action to a shell script. Here is the sql (MySQL) syntax I use. This gets run all the time for doing exactly what you are describing. It works like a charm. Even if you're not using MySQL, you should be able to accomplish the same thing with another database.

LOAD DATA INFILE "pathtofile/filename" REPLACE INTO TABLE tablename FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

NOTES:
a) depending on your platform, you may want to change the "lines terminated by" attribute (I'm using Mac OS X)
b) "replace" is optional. I use it because it's simpler and faster than searching and modifying individual records. It will, however, wipe out any existing data you have in the database, and I strongly recommend backing up your database prior to using it this way


Hope this helps.

Chris


On Apr 14, 2004, at 12:27 AM, Wayne Irvine wrote:


A client of mine insists on providing database updates in CSV format. And of
course some of the fields contain commas within the text. All the text
fields are double quoted.


I've written a bunch of assigns that replace ", and ," with [col] and then
remove all remaining " and it works just fine. Of course it would fail if
there were two number fields next to each other but that isn't the case.


This problem is as old as computers and must have been dealt with many
times. What sort of methods and procedures are people using?

BTW, this is an automated procedure run by a CRON job.

Wayne Irvine

                  Byte Services Pty Ltd
               http://www.byteserve.com.au/
                  [EMAIL PROTECTED]
   Ph 02 9960 6099   Mob 0409 960 609   Fax 02 9960 6088

_______________________________________________________________________ _
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf



________________________________________________________________________ TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

Reply via email to