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:
atabaseHandle:0x4065c0fc @trace_output=#<IO:0x402e7244>, @trace_mode=2, @handle=#<DBI:
BD::Mysql:
atabase: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:
BD::Mysql::Statement:0x40650054 @prep_stmt=#<DBI::SQL:
reparedStatement:0x4064fe38 @quoter=#<DBI:
BD::Mysql:
atabase: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:
BD::Mysql:
atabase: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
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:
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:
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