#!/usr/bin/env ruby

dsn,uid,pwd=ARGV[0,3]

require 'dbi'

# Connect to a database
dbh = DBI.connect("DBI:ODBC:"+dsn, uid, pwd)

# Drop and recreate the table to ensure it exists
begin 
  dbh.do("drop table test") 
rescue 
end

begin 
  dbh.do("create table test (id integer, str varchar(255))") 
rescue 
end

# Insert some rows, using a placeholder query
1.upto(10) do |i|
    sql = "insert into test values (?, ?)"
    dbh.do(sql, "#{i}", "This is a varchar #{(i*i*10).to_s}")
end 

# Select all rows from the table
sth = dbh.prepare('select * from test')
sth.execute

# Print out each row
while row=sth.fetch do
    p row
end

sth.finish
dbh.disconnect