rails/rails — pull request #10166 by gamache (2013-04-10 14:16:56+00:00)
Title: replace_bind_variables will no longer replace ?'s inside quotes

replace_bind_variables, as written, naively replaces all ?'s, whether or
not they were part of a quoted SQL string or identifier, resulting in an
arity error when quoted ?'s were present. This commit introduces proper
handling of ?'s within quotes, including handling of backslashed characters.

Code to reproduce the issue:

```ruby
class Foo < ActiveRecord::Base
attr_accessible :bar, :baz
end

Foo.where(%q{ bar = ? AND baz = 'quux?' }, 'bindvar')
# without patch => ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (1 for 2) in: bar = ? AND baz = 'quux?'
# with patch => #
```