Errors in mysql + ruby connection

Discussion in 'Ruby' started by Andrew Wallace, Jan 20, 2007.

  1. 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/.
     
    Andrew Wallace, Jan 20, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    985
    Mark Goldin
    Jan 17, 2004
  2. johnny
    Replies:
    1
    Views:
    803
    Jerry Hill
    Dec 8, 2006
  3. Randy Lawrence

    mysql-ruby or ruby-mysql?

    Randy Lawrence, May 23, 2004, in forum: Ruby
    Replies:
    3
    Views:
    114
    Randy Lawrence
    May 24, 2004
  4. Mer Gilmartin

    mysql-ruby module errors

    Mer Gilmartin, Sep 8, 2006, in forum: Ruby
    Replies:
    3
    Views:
    98
    Mer Gilmartin
    Nov 2, 2006
  5. Mark Meijer

    mySQL Ruby Gem and MAMP mySQL

    Mark Meijer, Feb 2, 2008, in forum: Ruby
    Replies:
    3
    Views:
    185
    louis
    Feb 3, 2008
Loading...

Share This Page