Newbie wants to know..FasterCSV or just CSV?

I’m trying to grab a CSV file from a user and let them upload it
directly to my database, but doing some minor checks on the data before
saving. Which is the easier way to implement this? CSV or FasterCSV? I
saw that perhaps there were some issues with FasterCSV and csv files
created from Mac versions of Excel.

Anyone have any experience with this and can recommend a newbie friendly
path?

Hi Vince

to me FasterCSV is quite easy to understand and use (before picking up
one
of those two, I had a look at both APIs but found FasterCSV more
intuitive).

Using excel CSV files exported on one platform (say PC) then imported on
another (say Mac) will cause troubles (I had those problems just two
days
ago!). It seems that the exported data is not stored in UTF-8 but in
ANSI,
with platform-specific codepage.

hope this helps.

Thibaut

Thibaut Barrère wrote:

to me FasterCSV is quite easy to understand and use (before picking up
one
of those two, I had a look at both APIs but found FasterCSV more
intuitive).

It’s just that documentation is a little sparse on using it. Are there
examples anywhere for having somebody upload a csv and then saving the
contents to a database? I’m trying to parse just four fields: title,
description, quantity, and price.

I saw a tip on rails.techno-weenie that uses migrations but couldn’t
quite make sense of it.

Using excel CSV files exported on one platform (say PC) then imported on
another (say Mac) will cause troubles

The clients could be anything (mac, win, linux) but the server is linux.
Does that mean I’ll have problems unless the csv is also exported from a
linux box? Is that an issue with the regular csv library too?

Thanks in advance…

If you can wait 8pm UTC+2 I’ll post a sample of how to do that (I’m
working
on something similar).

I can definitely wait. Thanks very much!

It’s just that documentation is a little sparse on using it. Are there
examples anywhere for having somebody upload a csv and then saving the
contents to a database? I’m trying to parse just four fields: title,
description, quantity, and price.

This library’s documentation doesn’t describe the file upload part of
course.

I’d suggest you write a unit test to play with the parsing part first,
using
sample CSV data, then deal with the upload thingy once you’re done
(‘step by
step, ouuh baby’ like they sing it).

If you can wait 8pm UTC+2 I’ll post a sample of how to do that (I’m
working
on something similar).

The clients could be anything (mac, win, linux) but the server is linux.

Does that mean I’ll have problems unless the csv is also exported from a
linux box? Is that an issue with the regular csv library too?

I think you’ll have the same issue with the regular csv. It’s more a
behaviour of excel export and an issue with encoding and codepages than
something caused by the library.

cheers

I seem to recall that FasterCSV is GPL, while CSV is the same license as
Ruby (MIT?). Repending on what you intend to do with your final
product, licensing choices may matter to you.

vince wrote:

I’m trying to grab a CSV file from a user and let them upload it
directly to my database, but doing some minor checks on the data before
saving. Which is the easier way to implement this? CSV or FasterCSV? I
saw that perhaps there were some issues with FasterCSV and csv files
created from Mac versions of Excel.

Anyone have any experience with this and can recommend a newbie friendly
path?

I can definitely wait. Thanks very much!

Hi

here’s a sample of what I’m using - here if you don’t have headers
defined
on the first line of the csv:

FasterCSV.foreach(File.dirname(__FILE__) 

+“/…/fixtures/answers.csv”,
:col_sep => ‘;’,
:headers => %w(id label question_number next_question_number
message))
do |row|
puts row[“label”]

end
end

all the options are explained here : http://fastercsv.rubyforge.org/

Asa: FasterCSV is “distributed under the user’s choice of the
GPLhttp://www.gnu.org/copyleft/gpl.html(see COPYING for details) or
the Ruby
software license http://www.ruby-lang.org/en/LICENSE.txt by James
Edward
Gray II.”, see http://fastercsv.rubyforge.org/files/LICENSE.html for
details

cheers

Thibaut