Subject Re: csv import into dbf
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 17 Aug 2024 16:51:06 +0200
Newsgroups dbase.getting-started

On 2024/08/17 14:36, Charlie wrote:
> I would like to allow the user to import a csv file with headers I suppose or in a certain order, into my table.  I know how to export to csv from a table, but am not sure how to start with import.  Any ideas or suggestions?  Thanks

Appending from a .csv file can be very simple or it can be fairly complex.

dBASE has a built-in mechanism for appending from .csv files but it has
severe limitations.

use whatever.dbf
append from whatever.csv delimited
use

The limitations are that dates in the .csv file must be in the format
...,yyyymmdd,... i.e no delimiter and no separator between year, month
and day.  It can't import into a memo field and it can't handle a .csv
file that has field names in the first line.  Basically, it can only
deal with .csv files created using the dBASE command  COPY TO
whatever.csv DELIMITED

Very few, if any, applications can handle, or create, .csv files that
meet these criteria so I created append_from_csv.prg which is in the
dUFLP. By setting various switches one should be able to import
virtually any .csv file.

As you have the field headers in your .csv file I assume you have used
usv_out.prg from the dUFLP to create it with dates in "mm/dd/yyyy" format.

If so,

set procedure to :duflp:append_from_csv.prg
append_from_csv('whatever.dbf',whatever.csv','a',true)


should do the trick.  As the switch to skip the first line is the 4th
parameter the third parameter (the date setting) also need to be set.

If it doesn't import correctly it means that there are other switches
that need to be set.  If you can't figure them out post the first data
line in your .csv file.

Mervyn