ruby/SQLite database interface

Hello,

I'm not sure this is quite the right place, but there do seem to be allot of posts with folks using ruby to play nicely with databases so I thought I would give it a go.

I am starting a long process of developing a database application bases on SQLite and ruby. This will run on various linux flavors as well as windows/cygwin. I am using ruby because the interface will eventually be browser based and ruby on rails or Sinatra seems like a good way to get that working. I have looked at some tutorials, but they are either too simple or too complicated. My first step is to do a simple import of a tab delimited text file to create a SQLlite database. There would be one database and several tables, so I need to know how to map each column in the file to table/column. It could be just one table for now if that is simpler.

Can some point me in the right direction to get me going? I have worked through allot of this tutorial,
SQLite Ruby tutorial

This code,


#!/usr/bin/ruby

require 'sqlite3'

begin
    
    db = SQLite3::Database.open "test.db"
    db.execute "CREATE TABLE IF NOT EXISTS Cars(Id INTEGER PRIMARY KEY, 
        Name TEXT, Price INT)"
    db.execute "INSERT INTO Cars VALUES(1,'Audi',52642)"
    db.execute "INSERT INTO Cars VALUES(2,'Mercedes',57127)"
    db.execute "INSERT INTO Cars VALUES(3,'Skoda',9000)"
    db.execute "INSERT INTO Cars VALUES(4,'Volvo',29000)"
    db.execute "INSERT INTO Cars VALUES(5,'Bentley',350000)"
    db.execute "INSERT INTO Cars VALUES(6,'Citroen',21000)"
    db.execute "INSERT INTO Cars VALUES(7,'Hummer',41400)"
    db.execute "INSERT INTO Cars VALUES(8,'Volkswagen',21600)"
    
rescue SQLite3::Exception => e 
    
    puts "Exception occured"
    puts e
    
ensure
    db.close if db
end

inserts some data to a table, but a hard coded comma separated list is a long way from a delimited text file. I think it's fine for the mapping to be hard coded for now, but this is something that would eventually be entered from a browser interface. At the end of the day, one function would be to select a file from a web interface and load it into a SQLite database. There would be mapping for each column in the file to a table/column in the database, and also a hash to determine if the record already exists. Where a record already exists, data could be added, where it doesn't exist, it will be created.

This is relatively straightforward stuff, but it always seems to take a while to get going.

I can post some sample files if that would help.

Thanks for the advice,

LMHmedchem

At the moment, I am trying to get the ruby-sqlite working under windows cygwin. The libsqlite3-ruby package does not appear to be in the current cygwin package manager. I have tried installing it with gem, but I don't appear to have gem, or there is something wrong with the configuration.

gem install sqlite3-ruby

gives,
-bash: gem: command not found

I presume this is a cygwin issue, but I need to get the sqlite3-ruby package working before I can get any further, or give up on a ruby interface and try some other interpreter. Can anyone give advice on how to get this working? I don't have the windows ruby package installed, just the cygwin version.

LMHmedchem