Run sql script from Ruby

Posted by Chaker Nakhli on Stack Overflow See other posts from Stack Overflow or by Chaker Nakhli
Published on 2010-03-09T15:54:11Z Indexed on 2010/03/25 14:43 UTC
Read the original article Hit count: 397

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about dbi