mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
working against arel/collector branch
This commit is contained in:
parent
70bd5eb4bb
commit
42a1bf18f2
4 changed files with 12 additions and 19 deletions
|
@ -9,7 +9,8 @@ module ActiveRecord
|
|||
# Converts an arel AST to SQL
|
||||
def to_sql(arel, binds = [])
|
||||
if arel.respond_to?(:ast)
|
||||
visitor.accept(arel.ast, collector).compile binds.dup
|
||||
collected = visitor.accept(arel.ast, collector)
|
||||
collected.compile(binds.dup, self)
|
||||
else
|
||||
arel
|
||||
end
|
||||
|
|
|
@ -183,10 +183,6 @@ module ActiveRecord
|
|||
INDEX_TYPES = [:fulltext, :spatial]
|
||||
INDEX_USINGS = [:btree, :hash]
|
||||
|
||||
class BindSubstitution < Arel::Visitors::MySQL # :nodoc:
|
||||
include Arel::Visitors::BindVisitor
|
||||
end
|
||||
|
||||
# FIXME: Make the first parameter more similar for the two adapters
|
||||
def initialize(connection, logger, connection_options, config)
|
||||
super(connection, logger)
|
||||
|
@ -203,21 +199,17 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
class BindCollector < Arel::Collectors::Bind
|
||||
def initialize(conn)
|
||||
@conn = conn
|
||||
super()
|
||||
end
|
||||
|
||||
def compile(bvs)
|
||||
super(bvs.map { |bv| @conn.quote(*bv.reverse) })
|
||||
def compile(bvs, conn)
|
||||
super(bvs.map { |bv| conn.quote(*bv.reverse) })
|
||||
end
|
||||
end
|
||||
|
||||
def collector
|
||||
if @prepared_statements
|
||||
raise
|
||||
Arel::Collectors::SQLString.new
|
||||
else
|
||||
BindCollector.new self
|
||||
BindCollector.new
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ module ActiveRecord
|
|||
|
||||
def initialize(connection, logger, connection_options, config)
|
||||
super
|
||||
@visitor = BindSubstitution.new self
|
||||
@prepared_statements = false
|
||||
configure_connection
|
||||
end
|
||||
|
||||
def cacheable_query(arel)
|
||||
ActiveRecord::StatementCache.partial_query visitor, arel.ast
|
||||
ActiveRecord::StatementCache.partial_query visitor, arel.ast, collector
|
||||
end
|
||||
|
||||
MAX_INDEX_LENGTH_FOR_UTF8MB4 = 191
|
||||
|
|
|
@ -28,7 +28,7 @@ module ActiveRecord
|
|||
|
||||
class PartialQuery < Query
|
||||
def sql_for(binds, connection)
|
||||
@sql.gsub(/\?/) { connection.quote(*binds.shift.reverse) }
|
||||
@sql.compile binds, connection
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,9 +36,9 @@ module ActiveRecord
|
|||
Query.new visitor.accept(ast, Arel::Collectors::SQLString.new).value
|
||||
end
|
||||
|
||||
def self.partial_query(visitor, ast)
|
||||
sql = visitor.accept(ast) { "?" }
|
||||
PartialQuery.new sql
|
||||
def self.partial_query(visitor, ast, collector)
|
||||
collected = visitor.accept(ast, collector)
|
||||
PartialQuery.new collected
|
||||
end
|
||||
|
||||
class Params
|
||||
|
|
Loading…
Reference in a new issue