Ensure that microsecond precision is only used for version of mysql that support it. Fixes #19711
This commit is contained in:
parent
a2bb266a7f
commit
e975d7cd1a
@ -107,6 +107,18 @@ def initialize(connection, logger = nil, pool = nil) #:nodoc:
|
||||
@prepared_statements = false
|
||||
end
|
||||
|
||||
class Version
|
||||
include Comparable
|
||||
|
||||
def initialize(version_string)
|
||||
@version = version_string.split('.').map(&:to_i)
|
||||
end
|
||||
|
||||
def <=>(version_string)
|
||||
@version <=> version_string.split('.').map(&:to_i)
|
||||
end
|
||||
end
|
||||
|
||||
class BindCollector < Arel::Collectors::Bind
|
||||
def compile(bvs, conn)
|
||||
casted_binds = conn.prepare_binds_for_database(bvs)
|
||||
|
@ -307,7 +307,7 @@ def supports_index_sort_order?
|
||||
#
|
||||
# http://bugs.mysql.com/bug.php?id=39170
|
||||
def supports_transaction_isolation?
|
||||
version[0] >= 5
|
||||
version >= '5.0.0'
|
||||
end
|
||||
|
||||
def supports_indexes_in_create?
|
||||
@ -319,11 +319,11 @@ def supports_foreign_keys?
|
||||
end
|
||||
|
||||
def supports_views?
|
||||
version[0] >= 5
|
||||
version >= '5.0.0'
|
||||
end
|
||||
|
||||
def supports_datetime_with_precision?
|
||||
(version[0] == 5 && version[1] >= 6) || version[0] >= 6
|
||||
version >= '5.6.4'
|
||||
end
|
||||
|
||||
def native_database_types
|
||||
@ -386,6 +386,14 @@ 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:
|
||||
@ -938,7 +946,7 @@ def subquery_for(key, select)
|
||||
end
|
||||
|
||||
def version
|
||||
@version ||= full_version.scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map(&:to_i)
|
||||
@version ||= Version.new(full_version.match(/^\d+\.\d+\.\d+/)[0])
|
||||
end
|
||||
|
||||
def mariadb?
|
||||
@ -946,7 +954,7 @@ def mariadb?
|
||||
end
|
||||
|
||||
def supports_rename_index?
|
||||
mariadb? ? false : (version[0] == 5 && version[1] >= 7) || version[0] >= 6
|
||||
mariadb? ? false : version >= '5.7.6'
|
||||
end
|
||||
|
||||
def configure_connection
|
||||
|
@ -65,18 +65,6 @@ class SQLite3Adapter < AbstractAdapter
|
||||
boolean: { name: "boolean" }
|
||||
}
|
||||
|
||||
class Version
|
||||
include Comparable
|
||||
|
||||
def initialize(version_string)
|
||||
@version = version_string.split('.').map(&:to_i)
|
||||
end
|
||||
|
||||
def <=>(version_string)
|
||||
@version <=> version_string.split('.').map(&:to_i)
|
||||
end
|
||||
end
|
||||
|
||||
class StatementPool < ConnectionAdapters::StatementPool
|
||||
private
|
||||
|
||||
|
@ -12,4 +12,18 @@ def test_type_cast_true
|
||||
def test_type_cast_false
|
||||
assert_equal 0, @conn.type_cast(false)
|
||||
end
|
||||
|
||||
def test_quoted_date_precision_for_gte_564
|
||||
@conn.stubs(:full_version).returns('5.6.4')
|
||||
@conn.remove_instance_variable(:@version)
|
||||
t = Time.now.change(usec: 1)
|
||||
assert_match(/\.000001\z/, @conn.quoted_date(t))
|
||||
end
|
||||
|
||||
def test_quoted_date_precision_for_lt_564
|
||||
@conn.stubs(:full_version).returns('5.6.3')
|
||||
@conn.remove_instance_variable(:@version)
|
||||
t = Time.now.change(usec: 1)
|
||||
refute_match(/\.000001\z/, @conn.quoted_date(t))
|
||||
end
|
||||
end
|
||||
|
21
activerecord/test/cases/adapters/mysql2/quoting_test.rb
Normal file
21
activerecord/test/cases/adapters/mysql2/quoting_test.rb
Normal file
@ -0,0 +1,21 @@
|
||||
require "cases/helper"
|
||||
|
||||
class Mysql2QuotingTest < ActiveRecord::Mysql2TestCase
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
end
|
||||
|
||||
test 'quoted date precision for gte 5.6.4' do
|
||||
@connection.stubs(:full_version).returns('5.6.4')
|
||||
@connection.remove_instance_variable(:@version)
|
||||
t = Time.now.change(usec: 1)
|
||||
assert_match(/\.000001\z/, @connection.quoted_date(t))
|
||||
end
|
||||
|
||||
test 'quoted date precision for lt 5.6.4' do
|
||||
@connection.stubs(:full_version).returns('5.6.3')
|
||||
@connection.remove_instance_variable(:@version)
|
||||
t = Time.now.change(usec: 1)
|
||||
refute_match(/\.000001\z/, @connection.quoted_date(t))
|
||||
end
|
||||
end
|
@ -47,7 +47,8 @@ def in_memory_db?
|
||||
|
||||
def mysql_56?
|
||||
current_adapter?(:MysqlAdapter, :Mysql2Adapter) &&
|
||||
ActiveRecord::Base.connection.send(:version).join(".") >= "5.6.0"
|
||||
ActiveRecord::Base.connection.send(:version) >= '5.6.0' &&
|
||||
ActiveRecord::Base.connection.send(:version) < '5.7.0'
|
||||
end
|
||||
|
||||
def mysql_enforcing_gtid_consistency?
|
||||
|
Loading…
Reference in New Issue
Block a user