How to use fastcsv?

Hi,

I am a newbie and I want to export an excel-file using fastcsv.

This is an example program from book Practical Ruby Gems:

My results aren't much better :frowning:

thufir@arrakis ~/csv $
thufir@arrakis ~/csv $ ruby import.rb
import.rb:9: undefined local variable or method `fastercsv' for
main:Object (NameError)
thufir@arrakis ~/csv $
thufir@arrakis ~/csv $ cat import.rb
require 'fastercsv'

csvdata = "one\n"
csvdata = "two\n"
csvdata = "three\n"

one = ""

fastercsv.parse(csvdata) do |row |
        one = *row
end
thufir@arrakis ~/csv $
thufir@arrakis ~/csv $ mysql -u root -ppassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.0.44-log Gentoo Linux mysql-5.0.44

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

The following runs without error and generates output :slight_smile:
However, it doesn't import data to the db yet :frowning:

RTFM at:
http://fastercsv.rubyforge.org/classes/FasterCSV.html

the code, data and db:

thufir@arrakis ~/csv $
thufir@arrakis ~/csv $ ruby import.rb
["one"]
["two"]
["three"]
thufir@arrakis ~/csv $
thufir@arrakis ~/csv $ cat import.rb
require 'rubygems'
require 'fastercsv'

infile = "data.csv"

FCSV.foreach(infile) do |row|
        p row
end
thufir@arrakis ~/csv $
thufir@arrakis ~/csv $ sqlite3 foo.sqlite3
SQLite version 3.4.1
Enter ".help" for instructions

.schema

CREATE TABLE foos (bar STRING);
CREATE TABLE schema_info (version integer);

SELECT * FROM foos;
.quit

thufir@arrakis ~/csv $

-Thufir