Errors in mysql + ruby connection

A

Andrew Wallace

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 method `fetch_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:in `each'
from dbtest.rb:14
from ./dbconnect.rb:9:in `with_db'
from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:429:in `connect'
from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:214:in `connect'
from ./dbconnect.rb:8:in `with_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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top