1 #!/usr/local/bin/ruby
2 require 'dbi'
3 begin
4 query = ''
5 File.open("mbo.sql"){|f| query << f.readlines.to_s}
6 sqlStatement = query
7 DBI.connect('DBI:pg:DeMolay','user','password') do |dbh|
8 dbh.select_all(sqlStatement) do | row |
9 puts row
10 end
11 end
12 rescue Exception=>e
13 p e
14 end
ted@acacia:DeMolay > ./test.rb
#<ArgumentError: wrong number of arguments(1 for 0)>
ted@acacia:DeMolay >
It appears to be issued on line 8, but my search of the reference
material doesn’t solve it.
I don’t see any error, your code runs fine for me after I adjust for the
connection string-- but I don’t have a postgreSQL server set up to test
with right now. Have you tested the SQL itself? So it’s either your
connection string or the SQL.
Also, why the reassignment of query to sqlStatement?
Beats me. I wouldn’t do that.
And you might want to change that rescue clause to something like:
rescue => emsg
puts emsg.to_s
puts emsg.backtrace
end
which will be a little more informative than a straight dump of the
exception object itself.