mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Support microsecond datetime precision on MariaDB 5.3+.
We support microsecond datetime precision for MySQL 5.6.4+. MariaDB has supported it since 5.3.0, but even 10.x versions return a compatible version string like `5.5.5-10.1.8-MariaDB-log` which we parse as 5.5.5, before MySQL supported microsecond precision. Specialize our version check to account for MariaDB to fix.
This commit is contained in:
parent
2080ff2872
commit
2224d06cfa
6 changed files with 56 additions and 24 deletions
|
@ -1,3 +1,7 @@
|
|||
* MariaDB 5.3+ supports microsecond datetime precision.
|
||||
|
||||
*Jeremy Daer*
|
||||
|
||||
* Delegate `empty?`, `none?` and `one?`. Now they can be invoked as model class methods.
|
||||
|
||||
Example:
|
||||
|
|
|
@ -121,7 +121,11 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def supports_datetime_with_precision?
|
||||
version >= '5.6.4'
|
||||
if mariadb?
|
||||
version >= '5.3.0'
|
||||
else
|
||||
version >= '5.6.4'
|
||||
end
|
||||
end
|
||||
|
||||
def supports_advisory_locks?
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
require "cases/helper"
|
||||
|
||||
class Mysql2DatetimePrecisionQuotingTest < ActiveRecord::Mysql2TestCase
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
end
|
||||
|
||||
test 'microsecond precision for MySQL gte 5.6.4' do
|
||||
stub_version '5.6.4'
|
||||
assert_microsecond_precision
|
||||
end
|
||||
|
||||
test 'no microsecond precision for MySQL lt 5.6.4' do
|
||||
stub_version '5.6.3'
|
||||
assert_no_microsecond_precision
|
||||
end
|
||||
|
||||
test 'microsecond precision for MariaDB gte 5.3.0' do
|
||||
stub_version '5.5.5-10.1.8-MariaDB-log'
|
||||
assert_microsecond_precision
|
||||
end
|
||||
|
||||
test 'no microsecond precision for MariaDB lt 5.3.0' do
|
||||
stub_version '5.2.9-MariaDB'
|
||||
assert_no_microsecond_precision
|
||||
end
|
||||
|
||||
private
|
||||
def assert_microsecond_precision
|
||||
assert_match_quoted_microsecond_datetime(/\.000001\z/)
|
||||
end
|
||||
|
||||
def assert_no_microsecond_precision
|
||||
assert_match_quoted_microsecond_datetime(/\d\z/)
|
||||
end
|
||||
|
||||
def assert_match_quoted_microsecond_datetime(match)
|
||||
assert_match match, @connection.quoted_date(Time.now.change(usec: 1))
|
||||
end
|
||||
|
||||
def stub_version(full_version_string)
|
||||
@connection.stubs(:full_version).returns(full_version_string)
|
||||
@connection.remove_instance_variable(:@version) if @connection.instance_variable_defined?(:@version)
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
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) if @connection.instance_variable_defined?(:@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) if @connection.instance_variable_defined?(:@version)
|
||||
t = Time.now.change(usec: 1)
|
||||
assert_no_match(/\.000001\z/, @connection.quoted_date(t))
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'cases/helper'
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
if ActiveRecord::Base.connection.supports_datetime_with_precision?
|
||||
if subsecond_precision_supported?
|
||||
class DateTimePrecisionTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
self.use_transactional_tests = false
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'cases/helper'
|
||||
require 'support/schema_dumping_helper'
|
||||
|
||||
if ActiveRecord::Base.connection.supports_datetime_with_precision?
|
||||
if subsecond_precision_supported?
|
||||
class TimePrecisionTest < ActiveRecord::TestCase
|
||||
include SchemaDumpingHelper
|
||||
self.use_transactional_tests = false
|
||||
|
|
Loading…
Reference in a new issue