aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-09 14:32:51 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-09 14:32:51 -0700
commitee54e9bb3a6d7ffcf756ec1e385399b92354cb6b (patch)
tree00040da70caddaa468ce801770e5c9a71602a154 /activerecord/lib/active_record
parent1794ac0197501c8d416c37769f2b5683d297ce6f (diff)
downloadrails-ee54e9bb3a6d7ffcf756ec1e385399b92354cb6b.tar.gz
rails-ee54e9bb3a6d7ffcf756ec1e385399b92354cb6b.tar.bz2
rails-ee54e9bb3a6d7ffcf756ec1e385399b92354cb6b.zip
add a bind collector, remove the bind visitor
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb7
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb28
3 files changed, 24 insertions, 15 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 7cd825abb9..11cd590672 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -10,9 +10,7 @@ module ActiveRecord
def to_sql(arel, binds = [])
if arel.respond_to?(:ast)
binds = binds.dup
- visitor.compile(arel.ast) do
- quote(*binds.shift.reverse)
- end
+ visitor.accept(arel.ast, collector).compile binds.dup
else
arel
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 605156c381..17f24dc4e0 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -130,16 +130,11 @@ module ActiveRecord
@owner = nil
end
- def unprepared_visitor
- self.class::BindSubstitution.new self
- end
-
def unprepared_statement
old_prepared_statements, @prepared_statements = @prepared_statements, false
- old_visitor, @visitor = @visitor, unprepared_visitor
yield
ensure
- @visitor, @prepared_statements = old_visitor, old_prepared_statements
+ @prepared_statements = old_prepared_statements
end
# Returns the human-readable name of the adapter. Use mixed case - one
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 2cb619881a..ef4b45cd43 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -123,10 +123,6 @@ module ActiveRecord
end
end
- class BindSubstitution < Arel::Visitors::SQLite # :nodoc:
- include Arel::Visitors::BindVisitor
- end
-
def initialize(connection, logger, config)
super(connection, logger)
@@ -135,11 +131,31 @@ module ActiveRecord
self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 }))
@config = config
+ @visitor = Arel::Visitors::SQLite.new self
+
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
- @visitor = Arel::Visitors::SQLite.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