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)}'"
|
"'#{quote_string(value.to_s)}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitize_as_sql_comment(value) # :nodoc:
|
||||||
|
value.to_s.gsub(%r{ (/ (?: | \g<1>) \*) \+? \s* | \s* (\* (?: | \g<2>) /) }x, "")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def type_casted_binds(binds)
|
def type_casted_binds(binds)
|
||||||
if binds.first.is_a?(Array)
|
if binds.first.is_a?(Array)
|
||||||
|
|
|
@ -10,7 +10,8 @@ module Arel # :nodoc: all
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
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
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_Limit(o, collector)
|
def visit_Arel_Nodes_Limit(o, collector)
|
||||||
|
|
|
@ -43,7 +43,8 @@ module Arel # :nodoc: all
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
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
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_Offset(o, collector)
|
def visit_Arel_Nodes_Offset(o, collector)
|
||||||
|
|
|
@ -82,7 +82,8 @@ module Arel # :nodoc: all
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
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
|
end
|
||||||
|
|
||||||
def get_offset_limit_clause(o)
|
def get_offset_limit_clause(o)
|
||||||
|
|
|
@ -219,7 +219,8 @@ module Arel # :nodoc: all
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_OptimizerHints(o, collector)
|
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
|
end
|
||||||
|
|
||||||
def collect_nodes_for(nodes, collector, spacer, connector = COMMA)
|
def collect_nodes_for(nodes, collector, spacer, connector = COMMA)
|
||||||
|
@ -785,10 +786,9 @@ module Arel # :nodoc: all
|
||||||
@connection.quote_column_name(name)
|
@connection.quote_column_name(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_as_sql_comment(o)
|
def sanitize_as_sql_comment(value)
|
||||||
o.expr.map { |v|
|
return value if Arel::Nodes::SqlLiteral === value
|
||||||
v.gsub(%r{ (/ (?: | \g<1>) \*) \+? \s* | \s* (\* (?: | \g<2>) /) }x, "")
|
@connection.sanitize_as_sql_comment(value)
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect_optimizer_hints(o, collector)
|
def collect_optimizer_hints(o, collector)
|
||||||
|
|
Loading…
Reference in a new issue