Agreed. This was more of an experimental proof of concept. I haven't added
tests for the negative case yet. Just felt like trying to see how the
internals work and what was possible.
On Apr 6, 2014 1:11 PM, "Olivier El Mekki" <notifications@github.com> wrote:

> In lib/activerecord_any_of/alternative_builder.rb:
>
> > @@ -71,7 +71,7 @@ class PositiveBuilder < Builder
> >
> >          def with_statement_cache
> >            if queries && queries_bind_values.any?
> > -            relation = where([queries.reduce(:or).to_sql, *queries_bind_values.map { |v| v[1] }])
> > +            relation = where([queries.reduce(:or).to_sql.gsub(/\=\ \$\d/, "= ?"), *queries_bind_values.map { |v| v[1] }])
>
> We can't use a substitution that simple, because it would edit
> occurrences of = $\d in string content, like :
>
> SELECT * FROM `foos` WHERE `description` = "hello = $1"
>
> Also, this has not only to be used here, but also in NegativeBuilder<https://github.com/oelmekki/activerecord_any_of/blob/5acb07019aa04d0f88e0e1c0d7f55681d13414a0/lib/activerecord_any_of/alternative_builder.rb#L94>
> .
>
> I suggest you factorize this as a new method for the parent class,
> Builder, that would return string content as is before trying to
> substitute wildcards. This could be :
>
> def unprepare_query( query )
>   query.gsub(/((?<!\\)'.*?(?<!\\)'|(?<!\\)".*?(?<!\\)")|(\=\ \$\d)/) do |match|
>     $2 and $2.gsub(/\=\ \$\d/, "= ?") or match
>   endend
>
> And would be called like this :
>
> relation = where([unprepare_query(queries.reduce(:or).to_sql), *queries_bind_values.map { |v| v[1] }])
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/oelmekki/activerecord_any_of/pull/19/files#r11327055>
> .
>