datamapper / do

DataObjects
147 stars 74 forks source link

quoting.rb: no implicit conversion from nil to integer #8

Closed jasmarc closed 11 years ago

jasmarc commented 13 years ago

My entities are defined as such.

I issue a query like this:

author = Author.first(:name.like => "%Knuth%")

And I get this error, which I've traced down to this line. I really don't understand it all. I've tried commenting out some of the surrounding code, thinking that the error was actually occurring on the line above line 12. I've added logging to the quote_string method that's being called on line 12 -- the problem's not there, as it doesn't even make it that far. So, something is going on in the case-when statement.

sql: SELECT `id`, `name` FROM `authors` WHERE `name` LIKE ? ORDER BY `id` LIMIT ? var: %Knuth%
 ~ no implicit conversion from nil to integer
/home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/data_objects-0.10.3/lib/data_objects/quoting.rb:12:in `quote_string': no implicit conversion from nil to integer (TypeError)
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/data_objects-0.10.3/lib/data_objects/quoting.rb:12:in `quote_value'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/data_objects-0.10.3/lib/data_objects/command.rb:69:in `block in escape_sql'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/data_objects-0.10.3/lib/data_objects/command.rb:61:in `gsub!'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/data_objects-0.10.3/lib/data_objects/command.rb:61:in `escape_sql'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:147:in `execute_reader'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:147:in `block in read'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:141:in `read'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/dm-core-1.1.0/lib/dm-core/repository.rb:162:in `read'
        from /home3/jrm425/usr/lib/ruby/gems/1.9.1/gems/dm-core-1.1.0/lib/dm-core/model.rb:370:in `first'
        from test.rb:10:in `<main>'

UPDATE: The problem is still on line 12 of quoting.rb, however I've noticed that something weird is going on with the call to quote_string. I made an exact copy of this method called myquotestring and replaced the call to quote_string with an equivalent call to my new method and things worked fine. There's obviously some meta-programming magic going on somewhere that I'm not aware of.

dbussink commented 13 years ago

What i see in the query is that there is just a single parameter passed and no value is present for the limit. Are you able to reproduce this issue with the latest version without using DataMapper?

dbussink commented 11 years ago

This isn't a problem with DO. If you look at the query generated you see there are two bind parameters in the query: LIKE ? and LIMIT ?. There seems to be only one variable bound, %Knuth%. In that case I can expect there being a problem.

Please check with in this case datamapper to see why the wrong query is being generated. @dkubb does this look like something you've seen before?