Skip to content

Commit

Permalink
Merge pull request rails#24374 from kamipo/move_quoting_methods_to_qu…
Browse files Browse the repository at this point in the history
…oting_module

Move quoting methods to `Quoting` module
  • Loading branch information
rafaelfranca committed Apr 6, 2016
2 parents 9c2945f + cc7f39a commit ce2cc06
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def schema_creation
class_attribute :emulate_booleans
self.emulate_booleans = true

QUOTED_TRUE, QUOTED_FALSE = '1', '0'

NATIVE_DATABASE_TYPES = {
primary_key: "int auto_increment PRIMARY KEY",
string: { name: "varchar", limit: 255 },
Expand Down Expand Up @@ -164,34 +162,6 @@ def error_number(exception) # :nodoc:
raise NotImplementedError
end

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

def quoted_true
QUOTED_TRUE
end

def unquoted_true
1
end

def quoted_false
QUOTED_FALSE
end

def unquoted_false
0
end

def quoted_date(value)
if supports_datetime_with_precision?
super
else
super.sub(/\.\d{6}\z/, '')
end
end

# REFERENTIAL INTEGRITY ====================================

def disable_referential_integrity #:nodoc:
Expand Down Expand Up @@ -939,8 +909,8 @@ def changed_in_place?(raw_old_value, new_value)
class MysqlString < Type::String # :nodoc:
def serialize(value)
case value
when true then QUOTED_TRUE
when false then QUOTED_FALSE
when true then MySQL::Quoting::QUOTED_TRUE
when false then MySQL::Quoting::QUOTED_FALSE
else super
end
end
Expand All @@ -949,8 +919,8 @@ def serialize(value)

def cast_value(value)
case value
when true then QUOTED_TRUE
when false then QUOTED_FALSE
when true then MySQL::Quoting::QUOTED_TRUE
when false then MySQL::Quoting::QUOTED_FALSE
else super
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module ActiveRecord
module ConnectionAdapters
module MySQL
module Quoting # :nodoc:
QUOTED_TRUE, QUOTED_FALSE = '1', '0'

def quote_column_name(name)
@quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`"
end
Expand All @@ -10,6 +12,30 @@ def quote_table_name(name)
@quoted_table_names[name] ||= super.gsub('.', '`.`')
end

def quoted_true
QUOTED_TRUE
end

def unquoted_true
1
end

def quoted_false
QUOTED_FALSE
end

def unquoted_false
0
end

def quoted_date(value)
if supports_datetime_with_precision?
super
else
super.sub(/\.\d{6}\z/, '')
end
end

private

def _quote(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ module ActiveRecord
module ConnectionAdapters
module SQLite3
module Quoting # :nodoc:
def quote_string(s)
@connection.class.quote(s)
end

def quote_table_name_for_assignment(table, attr)
quote_column_name(attr)
end

def quote_column_name(name)
@quoted_column_names[name] ||= %Q("#{super.gsub('"', '""')}")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,6 @@ def supports_explain?
true
end

# QUOTING ==================================================

def quote_string(s) #:nodoc:
@connection.class.quote(s)
end

def quote_table_name_for_assignment(table, attr)
quote_column_name(attr)
end

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

0 comments on commit ce2cc06

Please sign in to comment.