Joe Noon wrote:

Id like to import a csv, comma delimited file, into a table (sqlite3
db) in my Ruby application.  I can do it either of three ways:

1.) With a SQL statement like the COPY command.  Ive read this was
taken out, but then found a place that said it has been reimplemented?
Ive had no luck with anything Ive tried this route.

2.) I can execute a system command through code:
$> sqlite3 < myfile
Obviously that isnt the right syntax, but Im looking for the correct
syntax to import a csv into a specifc table from the command line like
that.

3.) I dont see how it would be possible to use the .import
functionality through code? If its possible please enlighten me.

Any helpful suggestions would be very much appreciated!

Joe Noon

Joe,

You can use a system call to execute a command like the following;

sqlite3 -separator , test.db ".import test.csv sometable"

You can of course change the file and table names when you build the command string to pass to the system call.

HTH
Dennis Cote

Reply via email to