Permalink
Browse files

fix bind collecting for mysql

  • Loading branch information...
1 parent ee54e9b commit 70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1 @tenderlove tenderlove committed Apr 9, 2014
View
@@ -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

0 comments on commit 70bd5eb

Please sign in to comment.