I have a ruby script which will read data from some CSV file and import them into sqlite database.
I can do this task easily from console using following command:
sqlite> .import <filename> <tablename>
sqlite> .import test.csv PROJECT_REPORT
How can I achieve the same form Ruby script ?
I am doing something similar like following(just a work arround):
CSV.foreach("timelog.csv") do |row|
database.execute("INSERT INTO PROJECT_REPORT(
Date,User,Activity,Comment)
values
(#{row[0]}, '#{row[1]}', '#{row[2]}', '#{row[3]}') ")
end
If it’s a one time job and you have a simple script that works why not stick with what you already have? If you need to grow the ruby script and want to expand it look at DataMapper (or on of the other ORMs) as an interface to your SQLite database. Create a simple class to contain your Date, User, Activiy and Comment fields and let DataMapper do the heavy lifting to the database.
Updated with datamapper example
Here’s a simple pseudo-example the datamapper implementation. This is not tested!
So to use it in your example above…
Obviously this isn’t a complete solution, but it will get you started.