Run sql script from Ruby
- by Chaker Nakhli
Hi all,
Using DBI::DatabaseHandle#execute or DBI::DatabaseHandle#prepare it's not possible to run an sql script (with mutiple sql statments). It fails with the following error :
ERROR: cannot insert multiple commands into a prepared statement
I tried to use the "unprepared" way using DBI::DatabaseHandle#do (the doc says it "goes straight to the DBD‘s implementation") but it keeps throwing the same error.
code snippet:
require 'dbd/pg'
require 'dbi'
DBI.connect("dbi:pg:database=dbname", db_user, db_password, db_params) do |dbh|
schema = IO::read(schema_file)
dbh.do(schema)
end
I'm using
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
dbi-0.4.3
dbd-pg-0.3.9
pg-0.9.0-x86-mswin32
Thank you!