aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-09 15:20:56 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-09 15:20:56 -0700
commit70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1 (patch)
tree93bbca057083dc56f4059f9e6c993ebb82033247 /activerecord/lib
parentee54e9bb3a6d7ffcf756ec1e385399b92354cb6b (diff)
downloadrails-70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1.tar.gz
rails-70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1.tar.bz2
rails-70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1.zip
fix bind collecting for mysql
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb24
2 files changed, 22 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index 11cd590672..f4885b19d6 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -9,7 +9,6 @@ module ActiveRecord
# 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
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index 7c8f020065..88c90b06bf 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -193,11 +193,31 @@ module ActiveRecord
@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