Dbd/mysql returns nil rows?

I find this very confusing. I’m trying to run a simple query using
ruby DBI and MySQL, and for some reason, the dbd driver is returning
nil instead of returning valid rows. It can’t be an SQL error, or
there would have been an exception thrown, right? So what am I doing
wrong?

Here’s an irb transcript:

irb(main):016:0> dbh = DBI.connect(“DBI:mysql:testplan”, “testplan”, “testplan”)
=> #<DBI::DatabaseHandle:0x4065c0fc @trace_output=#IO:0x402e7244, @trace_mode=2, @handle=#<DBI::DBD::Mysql::Database:0x4065bcd8 @have_transactions=true, @attr={“AutoCommit”=>true}, @handle=#Mysql:0x4065bcec, @mutex=#<Mutex:0x4065b65c @locked=false, @waiting=[]>>>
irb(main):017:0> mysth = dbh.prepare(“select * from #{CONFIG_TABLE} where #{CONFIG_PLATFORM} = ?”)
=> #<DBI::StatementHandle:0x40650068 @trace_output=#IO:0x402e7244, @prepared=true, @trace_mode=2, @fetchable=false, @row=nil, @handle=#<DBI::DBD::Mysql::Statement:0x40650054 @prep_stmt=#<DBI::SQL::PreparedStatement:0x4064fe38 @quoter=#<DBI::DBD::Mysql::Database:0x4065bcd8 @have_transactions=true, @attr={“AutoCommit”=>true}, @handle=#Mysql:0x4065bcec, @mutex=#<Mutex:0x4065b65c @locked=false, @waiting=[]>>, @unbound={1=>0}, @result=["select * from test_config where tc_platform = ", nil], @arg_index=1, @sql=“select * from test_config where tc_platform = ?”>, @attr={}, @params=[], @handle=#Mysql:0x4065bcec, @parent=#<DBI::DBD::Mysql::Database:0x4065bcd8 @have_transactions=true, @attr={“AutoCommit”=>true}, @handle=#Mysql:0x4065bcec, @mutex=#<Mutex:0x4065b65c @locked=false, @waiting=[]>>, @mutex=#<Mutex:0x4065b65c @locked=false, @waiting=[]>>, @cols=nil>
irb(main):018:0> rows = mysth.execute(10)
=> [nil, nil, nil, nil, nil]

Interestingly, it works fine with

rows = dbh.execute("…",10)

in irb, but in my application it gives the same result as the
prepare/execute pair above. If you guys can help me figure out why
irb is failing, then I can probably fix what’s broken in the app.

-=Eric

···


Eric Schwartz email: emschwar@hp.com
Hewlett-Packard Company Phone: +1 970 898 7443
Linux and Open Source Lab (LOSL)

Eric Schwartz emschwar@hp.com writes:

Interestingly, it works fine with

rows = dbh.execute(“…”,10)

Further interesting stuff:

sth = dbh.prepare(‘select * from table where id=10’)
rows = sth.execute()

also fail (each entry in rows() is NilClass).

It seems the problem may be in the prepare/execute combination
somewhere.

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.

Which version of Ruby and Ruby/DBI?

Regards,

Michael

···

On Thu, Dec 04, 2003 at 11:07:07AM +0900, Eric Schwartz wrote:

Eric Schwartz emschwar@hp.com writes:

Interestingly, it works fine with

rows = dbh.execute(“…”,10)

Further interesting stuff:

sth = dbh.prepare(‘select * from table where id=10’)
rows = sth.execute()

also fail (each entry in rows() is NilClass).

It seems the problem may be in the prepare/execute combination
somewhere.