mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract sanitize_as_sql_comment
from SQL visitor into connection
Probably that is useful for any other feature as well.
This commit is contained in:
parent
98d0f93506
commit
8072d8653a
5 changed files with 15 additions and 8 deletions
|
@ -138,6 +138,10 @@ module ActiveRecord
|
|||
"'#{quote_string(value.to_s)}'"
|
||||
end
|
||||
|
||||
def sanitize_as_sql_comment(value) # :nodoc:
|
||||
value.to_s.gsub(%r{ (/ (?: | \g<1>) \*) \+? \s* | \s* (\* (?: | \g<2>) /) }x, "")
|
||||
end
|
||||
|
||||
private
|
||||
def type_casted_binds(binds)
|
||||
if binds.first.is_a?(Array)
|
||||
|
|
|
@ -10,7 +10,8 @@ module Arel # :nodoc: all
|
|||
end
|
||||
|
||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
||||
collector << "/* <OPTGUIDELINES>#{sanitize_as_sql_comment(o).join}</OPTGUIDELINES> */"
|
||||
hints = o.expr.map { |v| sanitize_as_sql_comment(v) }.join
|
||||
collector << "/* <OPTGUIDELINES>#{hints}</OPTGUIDELINES> */"
|
||||
end
|
||||
|
||||
def visit_Arel_Nodes_Limit(o, collector)
|
||||
|
|
|
@ -43,7 +43,8 @@ module Arel # :nodoc: all
|
|||
end
|
||||
|
||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
||||
collector << "/*+ #{sanitize_as_sql_comment(o).join(", ")} */"
|
||||
hints = o.expr.map { |v| sanitize_as_sql_comment(v) }.join(", ")
|
||||
collector << "/*+ #{hints} */"
|
||||
end
|
||||
|
||||
def visit_Arel_Nodes_Offset(o, collector)
|
||||
|
|
|
@ -82,7 +82,8 @@ module Arel # :nodoc: all
|
|||
end
|
||||
|
||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
||||
collector << "OPTION (#{sanitize_as_sql_comment(o).join(", ")})"
|
||||
hints = o.expr.map { |v| sanitize_as_sql_comment(v) }.join(", ")
|
||||
collector << "OPTION (#{hints})"
|
||||
end
|
||||
|
||||
def get_offset_limit_clause(o)
|
||||
|
|
|
@ -219,7 +219,8 @@ module Arel # :nodoc: all
|
|||
end
|
||||
|
||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
||||
collector << "/*+ #{sanitize_as_sql_comment(o).join(" ")} */"
|
||||
hints = o.expr.map { |v| sanitize_as_sql_comment(v) }.join(" ")
|
||||
collector << "/*+ #{hints} */"
|
||||
end
|
||||
|
||||
def collect_nodes_for(nodes, collector, spacer, connector = COMMA)
|
||||
|
@ -785,10 +786,9 @@ module Arel # :nodoc: all
|
|||
@connection.quote_column_name(name)
|
||||
end
|
||||
|
||||
def sanitize_as_sql_comment(o)
|
||||
o.expr.map { |v|
|
||||
v.gsub(%r{ (/ (?: | \g<1>) \*) \+? \s* | \s* (\* (?: | \g<2>) /) }x, "")
|
||||
}
|
||||
def sanitize_as_sql_comment(value)
|
||||
return value if Arel::Nodes::SqlLiteral === value
|
||||
@connection.sanitize_as_sql_comment(value)
|
||||
end
|
||||
|
||||
def collect_optimizer_hints(o, collector)
|
||||
|
|
Loading…
Reference in a new issue