Skip to content

Commit 64f38c5

Browse files
aidanharanwpolicarpo
authored andcommitted
Set default time precision when registering time type
1 parent 5e4647e commit 64f38c5

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/active_record/connection_adapters/sqlserver/type/time.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ module SQLServer
44
module Type
55
class Time < ActiveRecord::Type::Time
66

7-
# Default fractional scale for 'time' (See https://docs.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql)
8-
DEFAULT_FRACTIONAL_SCALE = 7
9-
107
include TimeValueFractional2
118

129
def serialize(value)
@@ -45,7 +42,7 @@ def cast_value(value)
4542
end
4643

4744
def fractional_scale
48-
precision || DEFAULT_FRACTIONAL_SCALE
45+
precision
4946
end
5047

5148
end

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class SQLServerAdapter < AbstractAdapter
4141

4242
ADAPTER_NAME = 'SQLServer'.freeze
4343

44+
# Default precision for 'time' (See https://docs.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql)
45+
DEFAULT_TIME_PRECISION = 7
46+
4447
attr_reader :spid
4548

4649
cattr_accessor :cs_equality_operator, instance_accessor: false
@@ -297,8 +300,7 @@ def initialize_type_map(m = type_map)
297300
end
298301
m.register_type 'smalldatetime', SQLServer::Type::SmallDateTime.new
299302
m.register_type %r{\Atime}i do |sql_type|
300-
scale = extract_scale(sql_type)
301-
precision = extract_precision(sql_type)
303+
precision = extract_precision(sql_type) || DEFAULT_TIME_PRECISION
302304
SQLServer::Type::Time.new precision: precision
303305
end
304306
# Character Strings

0 commit comments

Comments
 (0)