Errors in mysql + ruby connection

Hi folks -
After getting my installation worked out, I’m having an error in my test
code that I just don’t understand. I am running on OS X (PowerPC).

Ruby 1.8.4
mySQL 5.0.27

I’m using DBI to access the database, borrowing code from the Ruby
Cookbook. The connection routine:

####################################################################
dbconnect.rb:
####################################################################
#!/usr/bin/ruby -w

require ‘rubygems’
require ‘dbi’

def with_db
DBI.connect(“DBI:Mysql:iskme_import:localhost”, “ISKME”,
“oerportal”) do |c|
yield c
end
end

And my test code:

####################################################################
#!/usr/bin/ruby -w

require ‘pp’
require ‘dbconnect’

sql = “SELECT * FROM AddItems”

sql = "INSERT INTO AddItems(type, iskme_id, native_id, title, url,
institution, collection, submitter) " +
“VALUES (‘C’,‘C000000299634946873’, ‘11’, ‘Too High for the
Supermarket’, +
" ‘http://www.diamondw.net/index.html’, " +
" ‘The Uninvited’, ‘13 Ways to Feel the Love’,
‘andyw’)”

with_db do |c|
c.execute(sql).each do |row|
pp [“GOT:”, row]
end
print “found #{rows} rows\n”
end

If I run the INSERT statement, I get this error:
/usr/local/lib/ruby/site_ruby/1.8/DBD/Mysql/Mysql.rb:601:in fetch': undefined methodfetch_row’ for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:659:in fetch' from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:684:ineach’
from dbtest.rb:14
from ./dbconnect.rb:9:in with_db' from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:429:inconnect’
from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:214:in connect' from ./dbconnect.rb:8:inwith_db’
from dbtest.rb:11

BUT, the record gets inserted (I use phpMyAdmin to administer the DB,
and I see the record). I just can’t figure out what’s happening here.
All help will be greatly appreciated.

Thanks,
Andy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs