Permalink
Browse files

Merge pull request #30651 from kamipo/4-2-stable-fix_datetime_precisi…

…on_for_mysql_adapter

4-2-stable: Fix datetime with precision for mysql adapter
  • Loading branch information...
eileencodes committed Sep 20, 2017
2 parents bb21cd2 + d9f95b6 commit 2ce72c86f62fe1ee375bdbca54acaff06124b2eb
@@ -282,6 +282,14 @@ def unquoted_false
0
end
def quoted_date(value)
if supports_datetime_with_precision? && value.acts_like?(:time) && value.respond_to?(:usec)
"#{super}.#{sprintf("%06d", value.usec)}"
else
super
end
end
# REFERENTIAL INTEGRITY ====================================
def disable_referential_integrity #:nodoc:
@@ -74,14 +74,6 @@ def quote_string(string)
@connection.escape(string)
end
def quoted_date(value)
if supports_datetime_with_precision? && value.acts_like?(:time) && value.respond_to?(:usec)
"#{super}.#{sprintf("%06d", value.usec)}"
else
super
end
end
#--
# CONNECTION MANAGEMENT ====================================
#++
@@ -282,6 +282,10 @@ def cast_value(value)
super
end
end
def has_precision?
precision || 0
end
end
class Time < Type::Time # :nodoc:
@@ -328,8 +332,11 @@ def find_type(field)
def initialize_type_map(m) # :nodoc:
super
m.register_type %r(datetime)i, Fields::DateTime.new
m.register_type %r(time)i, Fields::Time.new
m.register_type(%r(datetime)i) do |sql_type|
precision = extract_precision(sql_type)
Fields::DateTime.new(precision: precision)
end
end
def exec_without_stmt(sql, name = 'SQL') # :nodoc:
@@ -74,7 +74,7 @@ def mysql_datetime_precision(table_name, column_name)
result = results.find do |result_hash|
result_hash["column_name"] == column_name
end
result && result["datetime_precision"]
result && result["datetime_precision"].to_i
end
def activerecord_column_option(tablename, column_name, option)
@@ -46,9 +46,8 @@ def in_memory_db?
end
def mysql_56?
current_adapter?(:MysqlAdapter, :Mysql2Adapter) &&
ActiveRecord::Base.connection.send(:version) >= '5.6.0' &&
ActiveRecord::Base.connection.send(:version) < '5.7.0'
current_adapter?(:Mysql2Adapter) &&
ActiveRecord::Base.connection.send(:version) >= '5.6.0'
end
def mysql_enforcing_gtid_consistency?

0 comments on commit 2ce72c8

Please sign in to comment.