Percent sign wildcard ActiveRecord error
Reported by Adrian | January 3rd, 2008 @ 06:21 PM
Using MySQL 5.0 and the latest stable will_paginate from svn, I am getting the following error after passing a SQL query containing wildcards (ex. "select * from mytable where name like '%hello%'")
error: Too few arguments
Stack trace:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1418:in `%'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1418:in `sanitize_sql_array'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1387:in `sanitize_sql'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:59:in `paginate_by_sql'
vendor/plugins/will_paginate/lib/will_paginate/collection.rb:70:in `create'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:58:in `paginate_by_sql'
I tried escaping the %'s with backslashes to no avail.
Thanks very kindly for this wonderful plugin, which has allowed us to put our decrepit paging solution to bed!
Sincerely,
Adrian
Comments and changes to this ticket
-
Mislav January 4th, 2008 @ 01:36 PM
- Assigned user changed from Chris Wanstrath to Mislav
- State changed from new to open
- Title changed from Percent sign wildcard query error to Percent sign wildcard ActiveRecord error
Hey Adrian,
Thanks for the stack trace. Can I have the line where you call paginate_by_sql also?
While I track this down, please try if the same thing works with ActiveRecord from Rails 2.0. Could be an ActiveRecord issue.
-
Adrian January 4th, 2008 @ 01:42 PM
MIslav,
Please close this ticket. I am a knucklehead coming to Ruby from Python and didn't realize I had to put two percent signs together in order to prevent it from looking for a format string.
Thanks again for a super plug-in.
-
Mislav January 4th, 2008 @ 04:44 PM
- State changed from open to invalid
OK, but I still don't understand what was going on :)
-
Adrian January 4th, 2008 @ 05:15 PM
I had a query that looked like:
sql = "select * from mytable where name like '%hello%'"
but my query should have been written:
sql = "select * from mytable where name like '%%hello%%"
On Jan 4, 2008, at 10:44 AM, Lighthouse wrote:
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Everyone's favorite Ruby library for pagination of practically anything!