Skip to content

Instantly share code, notes, and snippets.

@eik3
Created September 1, 2009 17:09
Show Gist options
  • Save eik3/179231 to your computer and use it in GitHub Desktop.
Save eik3/179231 to your computer and use it in GitHub Desktop.
Ruby <-> SQLite3
fn="test.sqlite"
exit(1) if File.exist?(fn)
require 'rubygems'
require 'sqlite3'
db=SQLite3::Database.new(fn)
db.execute("CREATE TABLE testable (t1 INTEGER PRIMARY KEY, data TEXT, num DOUBLE, time DATE)")
db.execute(%^INSERT INTO testable (data,num,time) VALUES ('This is sample data',#{rand},"#{Time.now}")^)
puts db.execute("SELECT * FROM testable")
db.execute("DROP TABLE testable")
File.delete(fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment