LMHmedchem
06-27-2012, 07:45 PM
Hello to the forum,
I am starting a long process of developing a database application bases on SQLite and ruby. 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 the 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,
http://zetcode.com/db/sqliteruby/
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 the data, 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.
I can post some sample files if that would help.
Thanks for the advice,
LMHmedchem
I am starting a long process of developing a database application bases on SQLite and ruby. 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 the 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,
http://zetcode.com/db/sqliteruby/
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 the data, 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.
I can post some sample files if that would help.
Thanks for the advice,
LMHmedchem