fix bind collecting for mysql

This commit is contained in:
Aaron Patterson 2014-04-09 15:20:56 -07:00
parent ee54e9bb3a
commit 70bd5eb4bb
3 changed files with 22 additions and 4 deletions

@ -12,7 +12,6 @@ gem 'jquery-rails', '~> 3.1.0'
gem 'turbolinks'
gem 'coffee-rails', '~> 4.0.0'
gem 'arel', path: '/Users/aaron/git/arel'
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: '2-1-stable'
# require: false so bcrypt is loaded only when has_secure_password is used.
# This is to avoid ActiveModel (and by extension the entire framework)

@ -9,7 +9,6 @@ def initialize
# Converts an arel AST to SQL
def to_sql(arel, binds = [])
if arel.respond_to?(:ast)
binds = binds.dup
visitor.accept(arel.ast, collector).compile binds.dup
else
arel

@ -193,11 +193,31 @@ def initialize(connection, logger, connection_options, config)
@connection_options, @config = connection_options, config
@quoted_column_names, @quoted_table_names = {}, {}
@visitor = Arel::Visitors::MySQL.new self
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
@visitor = Arel::Visitors::MySQL.new self
else
@visitor = unprepared_visitor
@prepared_statements = false
end
end
class BindCollector < Arel::Collectors::Bind
def initialize(conn)
@conn = conn
super()
end
def compile(bvs)
super(bvs.map { |bv| @conn.quote(*bv.reverse) })
end
end
def collector
if @prepared_statements
Arel::Collectors::SQLString.new
else
BindCollector.new self
end
end