diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 15:20:56 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 15:20:56 -0700 |
commit | 70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1 (patch) | |
tree | 93bbca057083dc56f4059f9e6c993ebb82033247 | |
parent | ee54e9bb3a6d7ffcf756ec1e385399b92354cb6b (diff) | |
download | rails-70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1.tar.gz rails-70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1.tar.bz2 rails-70bd5eb4bb8d4b0e285bacb397f0ce39e9d5d1d1.zip |
fix bind collecting for mysql
3 files changed, 22 insertions, 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) 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 |