Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Percent sign wildcard ActiveRecord error

#173

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

Reported by Adrian · January 3rd, 2008 @ 06:21 PM

State: invalid
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Mislav
    Mislav
    • 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.

    January 4th, 2008 @ 01:36 PM

  2. Adrian
    Adrian

    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.

    January 4th, 2008 @ 01:42 PM

  3. Mislav
    Mislav
    • State changed from open to invalid

    OK, but I still don't understand what was going on :)

    January 4th, 2008 @ 04:44 PM

  4. Adrian
    Adrian

    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:

    January 4th, 2008 @ 05:15 PM

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.