If you do not want to use ActiveRecord, ORM may be a little more complicated for your use right now), you can still use the ruby-mysql library or even better IMHO - use the Ruby DBI / DBD library ( here ), which has DBD drivers for mysql and postgresql out of the box.
So you can issue direct SQL statements like this
require "dbi" require "dbi/dbrc" # == Configuration DB = "sympa" HOST = "saphir" cnt = 0 dup = 0 # == Crude option processing # list_name = ARGV.shift.to_s file = ARGV.shift.to_s db = DBI::DBRC.new(DB) DBI.connect(db.dsn + ":#{HOST}", db.user, db.password) do |dbh| date = Time.now.asctime if not list_name or list_name == "" then puts "List name is mandatory" exit 1 end req1 = <<-"EOR" insert into user_table (email_user,lang_user) values (?, ?) EOR ... req2 = <<-"EOR" insert into subscriber_table (user_subscriber, list_subscriber, visibility_subscriber, date_subscriber, reception_subscriber) values (?, ?, ?, NOW(), ?) EOR sth1 = dbh.prepare(req1) sth2 = dbh.prepare(req2) ... # # Insertion in user_table # begin sth1.execute(line, "en") cnt += 1 rescue DBI::DatabaseError => err $stderr.puts("DBI: #{err}") end
dbi / dbrc is a useful module that allows you not to enter the login and password directly into the script. See there .
Keltia
source share