dbd/mysql returns nil rows?

E

Eric Schwartz

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
 
E

Eric Schwartz

Eric Schwartz said:
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
 
M

Michael Neumann

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.

Which version of Ruby and Ruby/DBI?

Regards,

Michael
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top