I want to import data into an sqlite3 db, but am fuzzy as to how to declare variables to get that done.
For:
:name => name
Both of the above need to be initialized or defined somehow, but I don't know how.
thufir@arrakis ~/goodfellow-tool/db $ thufir@arrakis ~/goodfellow-tool/db $ ruby import.rb ["one"] import.rb:11: undefined local variable or method `name' for main:Object (NameError) from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/ faster_csv.rb:1458:in `each' from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/ faster_csv.rb:1003:in `foreach' from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/ faster_csv.rb:1175:in `open' from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/ faster_csv.rb:1002:in `foreach' from import.rb:8 thufir@arrakis ~/goodfellow-tool/db $ thufir@arrakis ~/goodfellow-tool/db $ cat import.rb require 'rubygems' require 'fastercsv' require '/home/thufir/goodfellow-tool/config/environment.rb'
infile = "data.csv"
FCSV.foreach(infile) do |row| p row Call.new( :name => name ) end thufir@arrakis ~/goodfellow-tool/db $ thufir@arrakis ~/goodfellow-tool/db $ sqlite3 development.sqlite3 SQLite version 3.4.1 Enter ".help" for instructions
.schema
CREATE TABLE calls ("id" INTEGER PRIMARY KEY NOT NULL, "name" varchar (255) DEFAULT NULL); CREATE TABLE schema_info (version integer);
SELECT * FROM calls;
1|zero
.quit
thufir@arrakis ~/goodfellow-tool/db $ thufir@arrakis ~/goodfellow-tool/db $ cat data.csv "one" "two" "three" thufir@arrakis ~/goodfellow-tool/db $
thanks,
Thufir