Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Errors in mysql + ruby connection

Reply
Thread Tools

Errors in mysql + ruby connection

 
 
Andrew Wallace
Guest
Posts: n/a
 
      01-20-2007
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mySQL Ruby Gem and MAMP mySQL Mark Meijer Ruby 3 02-03-2008 04:19 AM
mysql-ruby module errors Mer Gilmartin Ruby 3 11-02-2006 02:59 PM
ruby mysql errors -where am I going wrong here? Mer Gilmartin Ruby 12 11-02-2006 02:51 PM
mysql-ruby or ruby-mysql? Randy Lawrence Ruby 3 05-24-2004 03:30 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM



Advertisments