activerecord-jdbcsqlserver-adapter 50.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +27 -0
- data/CHANGELOG.md +124 -0
- data/CODE_OF_CONDUCT.md +31 -0
- data/Dockerfile +20 -0
- data/Gemfile +77 -0
- data/Guardfile +29 -0
- data/MIT-LICENSE +20 -0
- data/RAILS5-TODO.md +5 -0
- data/README.md +93 -0
- data/RUNNING_UNIT_TESTS.md +96 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/activerecord-jdbcsqlserver-adapter.gemspec +21 -0
- data/appveyor.yml +39 -0
- data/docker-compose.ci.yml +11 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +27 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +25 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/date_time.rb +58 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +47 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +49 -0
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +362 -0
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +67 -0
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +7 -0
- data/lib/active_record/connection_adapters/sqlserver/jdbc_overrides.rb +192 -0
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +99 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +34 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +16 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +517 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +66 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +66 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +22 -0
- data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +112 -0
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +64 -0
- data/lib/active_record/connection_adapters/sqlserver/type.rb +49 -0
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +21 -0
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +32 -0
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +30 -0
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +61 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +71 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +17 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +23 -0
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +21 -0
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/json.rb +11 -0
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +25 -0
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +25 -0
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +29 -0
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +68 -0
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +93 -0
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +25 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +21 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +26 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +24 -0
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +36 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +26 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +24 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +26 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +24 -0
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +146 -0
- data/lib/active_record/connection_adapters/sqlserver/version.rb +11 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +445 -0
- data/lib/active_record/connection_adapters/sqlserver_column.rb +28 -0
- data/lib/active_record/jdbc_sqlserver_connection_methods.rb +31 -0
- data/lib/active_record/sqlserver_base.rb +16 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +131 -0
- data/lib/activerecord-jdbcsqlserver-adapter.rb +24 -0
- data/lib/activerecord-sqlserver-adapter.rb +1 -0
- data/lib/arel/visitors/sqlserver.rb +205 -0
- data/lib/arel_sqlserver.rb +3 -0
- data/test/appveyor/dbsetup.ps1 +27 -0
- data/test/appveyor/dbsetup.sql +11 -0
- data/test/bin/wait-for.sh +79 -0
- data/test/cases/adapter_test_sqlserver.rb +430 -0
- data/test/cases/coerced_tests.rb +845 -0
- data/test/cases/column_test_sqlserver.rb +812 -0
- data/test/cases/connection_test_sqlserver.rb +71 -0
- data/test/cases/execute_procedure_test_sqlserver.rb +45 -0
- data/test/cases/fetch_test_sqlserver.rb +57 -0
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +76 -0
- data/test/cases/helper_sqlserver.rb +44 -0
- data/test/cases/index_test_sqlserver.rb +47 -0
- data/test/cases/json_test_sqlserver.rb +32 -0
- data/test/cases/migration_test_sqlserver.rb +61 -0
- data/test/cases/order_test_sqlserver.rb +147 -0
- data/test/cases/pessimistic_locking_test_sqlserver.rb +94 -0
- data/test/cases/rake_test_sqlserver.rb +169 -0
- data/test/cases/schema_dumper_test_sqlserver.rb +234 -0
- data/test/cases/schema_test_sqlserver.rb +54 -0
- data/test/cases/scratchpad_test_sqlserver.rb +8 -0
- data/test/cases/showplan_test_sqlserver.rb +65 -0
- data/test/cases/specific_schema_test_sqlserver.rb +180 -0
- data/test/cases/transaction_test_sqlserver.rb +91 -0
- data/test/cases/utils_test_sqlserver.rb +129 -0
- data/test/cases/uuid_test_sqlserver.rb +49 -0
- data/test/config.yml +38 -0
- data/test/debug.rb +14 -0
- data/test/fixtures/1px.gif +0 -0
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +11 -0
- data/test/models/sqlserver/booking.rb +3 -0
- data/test/models/sqlserver/customers_view.rb +3 -0
- data/test/models/sqlserver/datatype.rb +3 -0
- data/test/models/sqlserver/datatype_migration.rb +8 -0
- data/test/models/sqlserver/dollar_table_name.rb +3 -0
- data/test/models/sqlserver/dot_table_name.rb +3 -0
- data/test/models/sqlserver/edge_schema.rb +13 -0
- data/test/models/sqlserver/fk_has_fk.rb +3 -0
- data/test/models/sqlserver/fk_has_pk.rb +3 -0
- data/test/models/sqlserver/natural_pk_data.rb +4 -0
- data/test/models/sqlserver/natural_pk_int_data.rb +3 -0
- data/test/models/sqlserver/no_pk_data.rb +3 -0
- data/test/models/sqlserver/object_default.rb +3 -0
- data/test/models/sqlserver/quoted_table.rb +7 -0
- data/test/models/sqlserver/quoted_view_1.rb +3 -0
- data/test/models/sqlserver/quoted_view_2.rb +3 -0
- data/test/models/sqlserver/sst_memory.rb +3 -0
- data/test/models/sqlserver/string_default.rb +3 -0
- data/test/models/sqlserver/string_defaults_big_view.rb +3 -0
- data/test/models/sqlserver/string_defaults_view.rb +3 -0
- data/test/models/sqlserver/tinyint_pk.rb +3 -0
- data/test/models/sqlserver/upper.rb +3 -0
- data/test/models/sqlserver/uppered.rb +3 -0
- data/test/models/sqlserver/uuid.rb +3 -0
- data/test/schema/datatypes/2012.sql +55 -0
- data/test/schema/enable-in-memory-oltp.sql +81 -0
- data/test/schema/sqlserver_specific_schema.rb +238 -0
- data/test/support/coerceable_test_sqlserver.rb +49 -0
- data/test/support/connection_reflection.rb +34 -0
- data/test/support/load_schema_sqlserver.rb +29 -0
- data/test/support/minitest_sqlserver.rb +1 -0
- data/test/support/paths_sqlserver.rb +50 -0
- data/test/support/rake_helpers.rb +41 -0
- data/test/support/sql_counter_sqlserver.rb +28 -0
- data/test/support/test_in_memory_oltp.rb +15 -0
- metadata +310 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class Time < ActiveRecord::Type::Time
|
6
|
+
|
7
|
+
include TimeValueFractional2
|
8
|
+
|
9
|
+
def serialize(value)
|
10
|
+
value = super
|
11
|
+
return value unless value.acts_like?(:time)
|
12
|
+
time = value.to_s(:_sqlserver_time).tap do |v|
|
13
|
+
fraction = quote_fractional(value)
|
14
|
+
v << ".#{fraction}"
|
15
|
+
end
|
16
|
+
Data.new time, self
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined? JRUBY_VERSION
|
20
|
+
|
21
|
+
# Currently only called from our custom Time type for formatting
|
22
|
+
def _formatted(value)
|
23
|
+
"#{value.to_s(:_sqlserver_time)}.#{quote_fractional(value)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# @Override
|
27
|
+
# We do not want the Time object to be turned into a string
|
28
|
+
def serialize(value)
|
29
|
+
value = super
|
30
|
+
value.acts_like?(:time) ? CoreExt::Time._at_with_sql_type(value, self) : value
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def deserialize(value)
|
36
|
+
value.is_a?(Data) ? super(value.value) : super
|
37
|
+
end
|
38
|
+
|
39
|
+
def type_cast_for_schema(value)
|
40
|
+
serialize(value).quoted
|
41
|
+
end
|
42
|
+
|
43
|
+
def sqlserver_type
|
44
|
+
"time(#{precision.to_i})"
|
45
|
+
end
|
46
|
+
|
47
|
+
def quoted(value)
|
48
|
+
Utils.quote_string_single(value)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def cast_value(value)
|
54
|
+
value = super
|
55
|
+
return if value.blank?
|
56
|
+
value = value.change year: 2000, month: 01, day: 01
|
57
|
+
apply_seconds_precision(value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def fractional_scale
|
61
|
+
precision
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
|
6
|
+
module TimeValueFractional
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def apply_seconds_precision(value)
|
11
|
+
return value if !value.respond_to?(fractional_property) || value.send(fractional_property).zero?
|
12
|
+
value.change fractional_property => seconds_precision(value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def seconds_precision(value)
|
16
|
+
return 0 if fractional_scale == 0
|
17
|
+
seconds = value.send(fractional_property).to_f / fractional_operator.to_f
|
18
|
+
seconds = ((seconds * (1 / fractional_precision)).round / (1 / fractional_precision)).round(fractional_scale)
|
19
|
+
(seconds * fractional_operator).round(0).to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def quote_fractional(value)
|
23
|
+
return 0 if fractional_scale == 0
|
24
|
+
frac_seconds = seconds_precision(value)
|
25
|
+
seconds = (frac_seconds.to_f / fractional_operator.to_f).round(fractional_scale)
|
26
|
+
seconds.to_d.to_s.split('.').last.to(fractional_scale-1)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fractional_property
|
30
|
+
:usec
|
31
|
+
end
|
32
|
+
|
33
|
+
def fractional_digits
|
34
|
+
6
|
35
|
+
end
|
36
|
+
|
37
|
+
def fractional_operator
|
38
|
+
10 ** fractional_digits
|
39
|
+
end
|
40
|
+
|
41
|
+
def fractional_precision
|
42
|
+
0.00333
|
43
|
+
end
|
44
|
+
|
45
|
+
def fractional_scale
|
46
|
+
3
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
module TimeValueFractional2
|
52
|
+
|
53
|
+
include TimeValueFractional
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def seconds_precision(value)
|
58
|
+
return 0 if fractional_scale == 0
|
59
|
+
return value.nsec if fractional_scale >= fractional_digits
|
60
|
+
decimal_places = 10 ** (fractional_digits - fractional_scale)
|
61
|
+
value.nsec / decimal_places * decimal_places
|
62
|
+
end
|
63
|
+
|
64
|
+
def fractional_property
|
65
|
+
:nsec
|
66
|
+
end
|
67
|
+
|
68
|
+
def fractional_digits
|
69
|
+
9
|
70
|
+
end
|
71
|
+
|
72
|
+
def fractional_precision
|
73
|
+
0.0000001
|
74
|
+
end
|
75
|
+
|
76
|
+
def fractional_scale
|
77
|
+
precision
|
78
|
+
end
|
79
|
+
|
80
|
+
def fractional_max
|
81
|
+
999999999
|
82
|
+
end
|
83
|
+
|
84
|
+
def fractional_scale_max
|
85
|
+
('9' * fractional_scale) + ('0' * (fractional_digits - fractional_scale))
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class TinyInteger < Integer
|
6
|
+
|
7
|
+
def sqlserver_type
|
8
|
+
'tinyint'.freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def max_value
|
14
|
+
256
|
15
|
+
end
|
16
|
+
|
17
|
+
def min_value
|
18
|
+
0
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class UnicodeChar < UnicodeString
|
6
|
+
|
7
|
+
def type
|
8
|
+
:nchar
|
9
|
+
end
|
10
|
+
|
11
|
+
def sqlserver_type
|
12
|
+
'nchar'.tap do |type|
|
13
|
+
type << "(#{limit})" if limit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class UnicodeVarchar < UnicodeChar
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
@limit = 4000 if @limit.to_i == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
:string
|
14
|
+
end
|
15
|
+
|
16
|
+
def sqlserver_type
|
17
|
+
'nvarchar'.tap do |type|
|
18
|
+
type << "(#{limit})" if limit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class UnicodeVarcharMax < UnicodeVarchar
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
@limit = 2_147_483_647
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
:text
|
14
|
+
end
|
15
|
+
|
16
|
+
def sqlserver_type
|
17
|
+
'nvarchar(max)'.freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class Uuid < String
|
6
|
+
|
7
|
+
ACCEPTABLE_UUID = %r{\A\{?([a-fA-F0-9]{4}-?){8}\}?\z}x
|
8
|
+
|
9
|
+
alias_method :serialize, :deserialize
|
10
|
+
|
11
|
+
def type
|
12
|
+
:uuid
|
13
|
+
end
|
14
|
+
|
15
|
+
def sqlserver_type
|
16
|
+
'uniqueidentifier'.freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
def serialize(value)
|
20
|
+
return unless value
|
21
|
+
Data.new super, self
|
22
|
+
end
|
23
|
+
|
24
|
+
def cast(value)
|
25
|
+
value.to_s[ACCEPTABLE_UUID, 0]
|
26
|
+
end
|
27
|
+
|
28
|
+
def quoted(value)
|
29
|
+
Utils.quote_string_single(value) if value
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class Varbinary < Binary
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
@limit = 8000 if @limit.to_i == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
:varbinary
|
14
|
+
end
|
15
|
+
|
16
|
+
def sqlserver_type
|
17
|
+
'varbinary'.tap do |type|
|
18
|
+
type << "(#{limit})" if limit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class VarbinaryMax < Varbinary
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
@limit = 2_147_483_647
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
:binary
|
14
|
+
end
|
15
|
+
|
16
|
+
def sqlserver_type
|
17
|
+
'varbinary(max)'.freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module SQLServer
|
4
|
+
module Type
|
5
|
+
class Varchar < Char
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
@limit = 8000 if @limit.to_i == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
:varchar
|
14
|
+
end
|
15
|
+
|
16
|
+
def sqlserver_type
|
17
|
+
'varchar'.tap do |type|
|
18
|
+
type << "(#{limit})" if limit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|