Skip to content

Commit

Permalink
Move @quoted_{column|table}_names cache up to the abstract adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed Mar 30, 2016
1 parent a564fec commit 6b50a2b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
Expand Up @@ -82,7 +82,7 @@ def quote_string(s)

# Quotes the column name. Defaults to no quoting.
def quote_column_name(column_name)
column_name
column_name.to_s
end

# Quotes the table name. Defaults to column name quoting.
Expand Down
Expand Up @@ -106,6 +106,7 @@ def initialize(connection, logger = nil, config = {}) # :nodoc:
@schema_cache = SchemaCache.new self
@visitor = nil
@prepared_statements = false
@quoted_column_names, @quoted_table_names = {}, {}
end

class Version
Expand Down
Expand Up @@ -56,7 +56,6 @@ def schema_creation

def initialize(connection, logger, connection_options, config)
super(connection, logger, config)
@quoted_column_names, @quoted_table_names = {}, {}

@visitor = Arel::Visitors::MySQL.new self

Expand Down Expand Up @@ -165,15 +164,9 @@ def error_number(exception) # :nodoc:
raise NotImplementedError
end

#--
# QUOTING ==================================================

def quote_column_name(name) #:nodoc:
@quoted_column_names[name] ||= "`#{name.to_s.gsub('`', '``')}`"
end

def quote_table_name(name) #:nodoc:
@quoted_table_names[name] ||= quote_column_name(name).gsub('.', '`.`')
end
#++

def quoted_true
QUOTED_TRUE
Expand Down
Expand Up @@ -2,6 +2,14 @@ module ActiveRecord
module ConnectionAdapters
module MySQL
module Quoting # :nodoc:
def quote_column_name(name)
@quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`"
end

def quote_table_name(name)
@quoted_table_names[name] ||= super.gsub('.', '`.`')
end

private

def _quote(value)
Expand Down
Expand Up @@ -27,8 +27,8 @@ def quote_string(s) #:nodoc:
# - schema_name."table.name"
# - "schema.name".table_name
# - "schema.name"."table.name"
def quote_table_name(name)
Utils.extract_schema_qualified_name(name.to_s).quoted
def quote_table_name(name) # :nodoc:
@quoted_table_names[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted
end

# Quotes schema names for use in SQL queries.
Expand All @@ -41,8 +41,8 @@ def quote_table_name_for_assignment(table, attr)
end

# Quotes column names for use in SQL queries.
def quote_column_name(name) #:nodoc:
PGconn.quote_ident(name.to_s)
def quote_column_name(name) # :nodoc:
@quoted_column_names[name] ||= PGconn.quote_ident(super)
end

# Quote date/time values for use in SQL input.
Expand Down
Expand Up @@ -2,6 +2,10 @@ module ActiveRecord
module ConnectionAdapters
module SQLite3
module Quoting # :nodoc:
def quote_column_name(name)
@quoted_column_names[name] ||= %Q("#{super.gsub('"', '""')}")
end

private

def _quote(value)
Expand Down
Expand Up @@ -87,7 +87,6 @@ def initialize(connection, logger, connection_options, config)
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 }))

@visitor = Arel::Visitors::SQLite.new self
@quoted_column_names = {}

if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
@prepared_statements = true
Expand Down Expand Up @@ -187,10 +186,6 @@ def quote_table_name_for_assignment(table, attr)
quote_column_name(attr)
end

def quote_column_name(name) #:nodoc:
@quoted_column_names[name] ||= %Q("#{name.to_s.gsub('"', '""')}")
end

#--
# DATABASE STATEMENTS ======================================
#++
Expand Down

0 comments on commit 6b50a2b

Please sign in to comment.