activerecord-sqlserver-adapter 6.0.0.rc1 → 6.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +11 -5
- data/Guardfile +9 -8
- data/Rakefile +12 -16
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +3 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +0 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +1 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +3 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +35 -32
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +7 -12
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +0 -3
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +8 -8
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +7 -7
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +106 -103
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +6 -8
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +1 -4
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +4 -8
- data/lib/active_record/connection_adapters/sqlserver/type.rb +35 -35
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/json.rb +0 -1
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +6 -9
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +1 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +8 -11
- data/lib/active_record/connection_adapters/sqlserver/version.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +85 -83
- data/lib/active_record/connection_adapters/sqlserver_column.rb +0 -2
- data/lib/active_record/sqlserver_base.rb +1 -1
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +26 -32
- data/lib/activerecord-sqlserver-adapter.rb +1 -1
- data/lib/arel/visitors/sqlserver.rb +18 -14
- data/lib/arel_sqlserver.rb +2 -2
- data/test/cases/adapter_test_sqlserver.rb +161 -182
- data/test/cases/change_column_null_test_sqlserver.rb +12 -12
- data/test/cases/coerced_tests.rb +88 -270
- data/test/cases/column_test_sqlserver.rb +281 -283
- data/test/cases/connection_test_sqlserver.rb +15 -20
- data/test/cases/execute_procedure_test_sqlserver.rb +18 -20
- data/test/cases/fetch_test_sqlserver.rb +14 -22
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +12 -18
- data/test/cases/helper_sqlserver.rb +13 -15
- data/test/cases/in_clause_test_sqlserver.rb +9 -9
- data/test/cases/index_test_sqlserver.rb +13 -15
- data/test/cases/json_test_sqlserver.rb +23 -25
- data/test/cases/migration_test_sqlserver.rb +22 -28
- data/test/cases/order_test_sqlserver.rb +51 -54
- data/test/cases/pessimistic_locking_test_sqlserver.rb +25 -33
- data/test/cases/rake_test_sqlserver.rb +31 -45
- data/test/cases/schema_dumper_test_sqlserver.rb +104 -108
- data/test/cases/schema_test_sqlserver.rb +18 -26
- data/test/cases/scratchpad_test_sqlserver.rb +2 -4
- data/test/cases/showplan_test_sqlserver.rb +24 -33
- data/test/cases/specific_schema_test_sqlserver.rb +66 -65
- data/test/cases/transaction_test_sqlserver.rb +16 -19
- data/test/cases/trigger_test_sqlserver.rb +12 -12
- data/test/cases/utils_test_sqlserver.rb +68 -70
- data/test/cases/uuid_test_sqlserver.rb +11 -13
- data/test/debug.rb +6 -6
- data/test/migrations/create_clients_and_change_column_null.rb +1 -1
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +2 -4
- data/test/models/sqlserver/booking.rb +1 -1
- data/test/models/sqlserver/customers_view.rb +1 -1
- data/test/models/sqlserver/dollar_table_name.rb +1 -1
- data/test/models/sqlserver/edge_schema.rb +1 -3
- data/test/models/sqlserver/fk_has_fk.rb +1 -1
- data/test/models/sqlserver/fk_has_pk.rb +1 -1
- data/test/models/sqlserver/natural_pk_data.rb +2 -2
- data/test/models/sqlserver/natural_pk_int_data.rb +1 -1
- data/test/models/sqlserver/no_pk_data.rb +1 -1
- data/test/models/sqlserver/object_default.rb +1 -1
- data/test/models/sqlserver/quoted_table.rb +2 -2
- data/test/models/sqlserver/quoted_view_1.rb +1 -1
- data/test/models/sqlserver/quoted_view_2.rb +1 -1
- data/test/models/sqlserver/sst_memory.rb +1 -1
- data/test/models/sqlserver/string_default.rb +1 -1
- data/test/models/sqlserver/string_defaults_big_view.rb +1 -1
- data/test/models/sqlserver/string_defaults_view.rb +1 -1
- data/test/models/sqlserver/tinyint_pk.rb +1 -1
- data/test/models/sqlserver/trigger.rb +2 -2
- data/test/models/sqlserver/trigger_history.rb +1 -1
- data/test/models/sqlserver/upper.rb +1 -1
- data/test/models/sqlserver/uppered.rb +1 -1
- data/test/models/sqlserver/uuid.rb +1 -1
- data/test/schema/sqlserver_specific_schema.rb +20 -22
- data/test/support/coerceable_test_sqlserver.rb +1 -4
- data/test/support/connection_reflection.rb +1 -2
- data/test/support/core_ext/query_cache.rb +1 -1
- data/test/support/load_schema_sqlserver.rb +3 -5
- data/test/support/minitest_sqlserver.rb +1 -1
- data/test/support/paths_sqlserver.rb +9 -11
- data/test/support/rake_helpers.rb +12 -10
- data/test/support/sql_counter_sqlserver.rb +0 -4
- data/test/support/test_in_memory_oltp.rb +7 -7
- metadata +5 -4
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class SmallDateTime < DateTime
|
8
|
-
|
9
8
|
def type
|
10
9
|
:smalldatetime
|
11
10
|
end
|
@@ -23,7 +22,6 @@ module ActiveRecord
|
|
23
22
|
def apply_seconds_precision(value)
|
24
23
|
value.change usec: 0 if value
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class String < ActiveRecord::Type::String
|
8
|
-
|
9
8
|
def changed_in_place?(raw_old_value, new_value)
|
10
9
|
if raw_old_value.is_a?(Data)
|
11
10
|
raw_old_value.value != new_value
|
@@ -13,7 +12,6 @@ module ActiveRecord
|
|
13
12
|
super
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class Time < ActiveRecord::Type::Time
|
8
|
-
|
9
8
|
include TimeValueFractional2
|
10
9
|
|
11
10
|
def serialize(value)
|
@@ -13,7 +12,7 @@ module ActiveRecord
|
|
13
12
|
return value unless value.acts_like?(:time)
|
14
13
|
|
15
14
|
time = "#{value.to_s(:_sqlserver_time)}.#{quote_fractional(value)}"
|
16
|
-
|
15
|
+
|
17
16
|
Data.new time, self
|
18
17
|
end
|
19
18
|
|
@@ -38,6 +37,7 @@ module ActiveRecord
|
|
38
37
|
def cast_value(value)
|
39
38
|
value = super
|
40
39
|
return if value.blank?
|
40
|
+
|
41
41
|
value = value.change year: 2000, month: 01, day: 01
|
42
42
|
apply_seconds_precision(value)
|
43
43
|
end
|
@@ -45,7 +45,6 @@ module ActiveRecord
|
|
45
45
|
def fractional_scale
|
46
46
|
precision
|
47
47
|
end
|
48
|
-
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
@@ -4,18 +4,18 @@ module ActiveRecord
|
|
4
4
|
module ConnectionAdapters
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
|
-
|
8
7
|
module TimeValueFractional
|
9
|
-
|
10
8
|
private
|
11
9
|
|
12
10
|
def apply_seconds_precision(value)
|
13
11
|
return value if !value.respond_to?(fractional_property) || value.send(fractional_property).zero?
|
12
|
+
|
14
13
|
value.change fractional_property => seconds_precision(value)
|
15
14
|
end
|
16
15
|
|
17
16
|
def seconds_precision(value)
|
18
17
|
return 0 if fractional_scale == 0
|
18
|
+
|
19
19
|
seconds = value.send(fractional_property).to_f / fractional_operator.to_f
|
20
20
|
seconds = ((seconds * (1 / fractional_precision)).round / (1 / fractional_precision)).round(fractional_scale)
|
21
21
|
(seconds * fractional_operator).round(0).to_i
|
@@ -23,9 +23,10 @@ module ActiveRecord
|
|
23
23
|
|
24
24
|
def quote_fractional(value)
|
25
25
|
return 0 if fractional_scale == 0
|
26
|
+
|
26
27
|
frac_seconds = seconds_precision(value)
|
27
28
|
seconds = (frac_seconds.to_f / fractional_operator.to_f).round(fractional_scale)
|
28
|
-
seconds.to_d.to_s.split(
|
29
|
+
seconds.to_d.to_s.split(".").last.to(fractional_scale - 1)
|
29
30
|
end
|
30
31
|
|
31
32
|
def fractional_property
|
@@ -37,7 +38,7 @@ module ActiveRecord
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def fractional_operator
|
40
|
-
10
|
41
|
+
10**fractional_digits
|
41
42
|
end
|
42
43
|
|
43
44
|
def fractional_precision
|
@@ -47,11 +48,9 @@ module ActiveRecord
|
|
47
48
|
def fractional_scale
|
48
49
|
3
|
49
50
|
end
|
50
|
-
|
51
51
|
end
|
52
52
|
|
53
53
|
module TimeValueFractional2
|
54
|
-
|
55
54
|
include TimeValueFractional
|
56
55
|
|
57
56
|
private
|
@@ -82,11 +81,9 @@ module ActiveRecord
|
|
82
81
|
end
|
83
82
|
|
84
83
|
def fractional_scale_max
|
85
|
-
(
|
84
|
+
("9" * fractional_scale) + ("0" * (fractional_digits - fractional_scale))
|
86
85
|
end
|
87
|
-
|
88
86
|
end
|
89
|
-
|
90
87
|
end
|
91
88
|
end
|
92
89
|
end
|
@@ -5,18 +5,16 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class UnicodeChar < UnicodeString
|
8
|
-
|
9
8
|
def type
|
10
9
|
:nchar
|
11
10
|
end
|
12
11
|
|
13
12
|
def sqlserver_type
|
14
|
-
|
13
|
+
"nchar".yield_self do |type|
|
15
14
|
type += "(#{limit})" if limit
|
16
15
|
type
|
17
16
|
end
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class UnicodeVarcharMax < UnicodeVarchar
|
8
|
-
|
9
8
|
def initialize(**args)
|
10
9
|
super
|
11
10
|
@limit = 2_147_483_647
|
@@ -18,7 +17,6 @@ module ActiveRecord
|
|
18
17
|
def sqlserver_type
|
19
18
|
"nvarchar(max)"
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class Uuid < String
|
8
|
-
|
9
8
|
ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x
|
10
9
|
|
11
10
|
alias_method :serialize, :deserialize
|
@@ -20,6 +19,7 @@ module ActiveRecord
|
|
20
19
|
|
21
20
|
def serialize(value)
|
22
21
|
return unless value
|
22
|
+
|
23
23
|
Data.new super, self
|
24
24
|
end
|
25
25
|
|
@@ -30,7 +30,6 @@ module ActiveRecord
|
|
30
30
|
def quoted(value)
|
31
31
|
Utils.quote_string_single(value) if value
|
32
32
|
end
|
33
|
-
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class Varbinary < Binary
|
8
|
-
|
9
8
|
def initialize(**args)
|
10
9
|
super
|
11
10
|
@limit = 8000 if @limit.to_i == 0
|
@@ -16,12 +15,11 @@ module ActiveRecord
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def sqlserver_type
|
19
|
-
|
18
|
+
"varbinary".yield_self do |type|
|
20
19
|
type += "(#{limit})" if limit
|
21
20
|
type
|
22
21
|
end
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class VarbinaryMax < Varbinary
|
8
|
-
|
9
8
|
def initialize(**args)
|
10
9
|
super
|
11
10
|
@limit = 2_147_483_647
|
@@ -18,7 +17,6 @@ module ActiveRecord
|
|
18
17
|
def sqlserver_type
|
19
18
|
"varbinary(max)"
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class Varchar < Char
|
8
|
-
|
9
8
|
def initialize(**args)
|
10
9
|
super
|
11
10
|
@limit = 8000 if @limit.to_i == 0
|
@@ -16,12 +15,11 @@ module ActiveRecord
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def sqlserver_type
|
19
|
-
|
18
|
+
"varchar".yield_self do |type|
|
20
19
|
type += "(#{limit})" if limit
|
21
20
|
type
|
22
21
|
end
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -5,7 +5,6 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module Type
|
7
7
|
class VarcharMax < Varchar
|
8
|
-
|
9
8
|
def initialize(**args)
|
10
9
|
super
|
11
10
|
@limit = 2_147_483_647
|
@@ -18,7 +17,6 @@ module ActiveRecord
|
|
18
17
|
def sqlserver_type
|
19
18
|
"varchar(max)"
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "strscan"
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
6
|
module ConnectionAdapters
|
7
7
|
module SQLServer
|
8
8
|
module Utils
|
9
|
-
|
10
|
-
QUOTED_STRING_PREFIX = 'N'
|
9
|
+
QUOTED_STRING_PREFIX = "N"
|
11
10
|
|
12
11
|
# Value object to return identifiers from SQL Server names http://bit.ly/1CZ3EiL
|
13
12
|
# Inspiried from Rails PostgreSQL::Name adapter object in their own Utils.
|
14
13
|
#
|
15
14
|
class Name
|
16
|
-
|
17
15
|
SEPARATOR = "."
|
18
16
|
UNQUOTED_SCANNER = /\]?\./
|
19
17
|
QUOTED_SCANNER = /\A\[.*?\]\./
|
@@ -56,15 +54,15 @@ module ActiveRecord
|
|
56
54
|
end
|
57
55
|
|
58
56
|
def quoted
|
59
|
-
parts.map{ |p| quote(p) if p }.join SEPARATOR
|
57
|
+
parts.map { |p| quote(p) if p }.join SEPARATOR
|
60
58
|
end
|
61
59
|
|
62
60
|
def quoted_raw
|
63
61
|
quote @raw_name
|
64
62
|
end
|
65
63
|
|
66
|
-
def ==(
|
67
|
-
|
64
|
+
def ==(other)
|
65
|
+
other.class == self.class && other.parts == parts
|
68
66
|
end
|
69
67
|
alias_method :eql?, :==
|
70
68
|
|
@@ -77,6 +75,7 @@ module ActiveRecord
|
|
77
75
|
def parse_raw_name
|
78
76
|
@parts = []
|
79
77
|
return if raw_name.blank?
|
78
|
+
|
80
79
|
scanner = StringScanner.new(raw_name)
|
81
80
|
matched = scanner.exist?(QUOTED_CHECKER) ? scanner.scan_until(QUOTED_SCANNER) : scanner.scan_until(UNQUOTED_SCANNER)
|
82
81
|
while matched
|
@@ -93,7 +92,7 @@ module ActiveRecord
|
|
93
92
|
@schema = @parts.first
|
94
93
|
end
|
95
94
|
rest = scanner.rest
|
96
|
-
rest = rest.starts_with?(
|
95
|
+
rest = rest.starts_with?(".") ? rest[1..-1] : rest[0..-1]
|
97
96
|
@object = unquote(rest)
|
98
97
|
@parts << @object
|
99
98
|
end
|
@@ -103,7 +102,7 @@ module ActiveRecord
|
|
103
102
|
end
|
104
103
|
|
105
104
|
def unquote(part)
|
106
|
-
if part && part.start_with?(
|
105
|
+
if part && part.start_with?("[")
|
107
106
|
part[1..-2]
|
108
107
|
else
|
109
108
|
part
|
@@ -113,7 +112,6 @@ module ActiveRecord
|
|
113
112
|
def parts
|
114
113
|
@parts
|
115
114
|
end
|
116
|
-
|
117
115
|
end
|
118
116
|
|
119
117
|
extend self
|
@@ -141,7 +139,6 @@ module ActiveRecord
|
|
141
139
|
def extract_identifiers(name)
|
142
140
|
SQLServer::Utils::Name.new(name)
|
143
141
|
end
|
144
|
-
|
145
142
|
end
|
146
143
|
end
|
147
144
|
end
|