Skip to content

Commit

Permalink
Extract simplified_type into the abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Aug 29, 2011
1 parent 5766539 commit 4fcd847
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ActiveRecord
module ConnectionAdapters
class AbstractMysqlAdapter < AbstractAdapter
class Column < ConnectionAdapters::Column
class Column < ConnectionAdapters::Column # :nodoc:
def extract_default(default)
if sql_type =~ /blob/i || type == :text
if default.blank?
Expand All @@ -23,8 +23,25 @@ def has_default?
super
end

# Must return the relevant concrete adapter
def adapter
raise NotImplementedError
end

private

def simplified_type(field_type)
return :boolean if adapter.emulate_booleans && field_type.downcase.index("tinyint(1)")

case field_type
when /enum/i, /set/i then :string
when /year/i then :integer
when /bit/i then :binary
else
super
end
end

def extract_limit(sql_type)
case sql_type
when /blob|text/i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,10 @@ def self.mysql2_connection(config)

module ConnectionAdapters
class Mysql2Adapter < AbstractMysqlAdapter
class Column < AbstractMysqlAdapter::Column # :nodoc:
BOOL = "tinyint(1)"

private

# FIXME: Combine with the mysql version and move to abstract adapter
def simplified_type(field_type)
return :boolean if Mysql2Adapter.emulate_booleans && field_type.downcase.index(BOOL)

case field_type
when /enum/i, /set/i then :string
when /year/i then :integer
when /bit/i then :binary
else
super
end
class Column < AbstractMysqlAdapter::Column # :nodoc:
def adapter
Mysql2Adapter
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module ConnectionAdapters
# * <tt>:sslcipher</tt> - Necessary to use MySQL with an SSL connection.
#
class MysqlAdapter < AbstractMysqlAdapter

class Column < AbstractMysqlAdapter::Column #:nodoc:
def self.string_to_time(value)
return super unless Mysql::Time === value
Expand All @@ -82,13 +83,8 @@ def self.string_to_date(v)
new_date(v.year, v.month, v.day)
end

private

# FIXME: Combine with the mysql2 version and move to abstract adapter
def simplified_type(field_type)
return :boolean if MysqlAdapter.emulate_booleans && field_type.downcase.index("tinyint(1)")
return :string if field_type =~ /enum/i
super
def adapter
MysqlAdapter
end
end

Expand Down

0 comments on commit 4fcd847

Please sign in to comment.