activerecord-sqlserver-adapter 5.2.1 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.editorconfig +9 -0
- data/.github/issue_template.md +23 -0
- data/.github/workflows/ci.yml +26 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +58 -20
- data/{Dockerfile → Dockerfile.ci} +1 -1
- data/Gemfile +48 -41
- data/Guardfile +9 -8
- data/README.md +28 -31
- data/RUNNING_UNIT_TESTS.md +3 -0
- data/Rakefile +14 -16
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +25 -14
- data/appveyor.yml +24 -17
- data/docker-compose.ci.yml +7 -5
- data/guides/RELEASING.md +11 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +2 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +3 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +5 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +2 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +8 -7
- data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +36 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +6 -4
- data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +9 -0
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +88 -44
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +9 -12
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +46 -8
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +16 -5
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +9 -7
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +210 -163
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +8 -8
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +4 -2
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +3 -1
- data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +43 -44
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +7 -9
- data/lib/active_record/connection_adapters/sqlserver/type.rb +38 -35
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +5 -4
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +7 -4
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +4 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +8 -8
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +5 -4
- data/lib/active_record/connection_adapters/sqlserver/type/decimal_without_scale.rb +22 -0
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/json.rb +2 -1
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +4 -4
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +4 -4
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +6 -6
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +8 -9
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +5 -4
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +6 -5
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +4 -4
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +4 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +6 -5
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +4 -4
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +6 -5
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +4 -4
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +10 -11
- data/lib/active_record/connection_adapters/sqlserver/version.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +145 -94
- data/lib/active_record/connection_adapters/sqlserver_column.rb +9 -5
- data/lib/active_record/sqlserver_base.rb +9 -1
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +28 -32
- data/lib/activerecord-sqlserver-adapter.rb +3 -1
- data/lib/arel/visitors/sqlserver.rb +108 -34
- data/lib/arel_sqlserver.rb +4 -2
- data/test/appveyor/dbsetup.ps1 +4 -4
- data/test/cases/adapter_test_sqlserver.rb +246 -171
- data/test/cases/change_column_null_test_sqlserver.rb +14 -12
- data/test/cases/coerced_tests.rb +722 -381
- data/test/cases/column_test_sqlserver.rb +287 -285
- data/test/cases/connection_test_sqlserver.rb +17 -20
- data/test/cases/execute_procedure_test_sqlserver.rb +20 -20
- data/test/cases/fetch_test_sqlserver.rb +16 -22
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +15 -19
- data/test/cases/helper_sqlserver.rb +15 -15
- data/test/cases/in_clause_test_sqlserver.rb +36 -0
- data/test/cases/index_test_sqlserver.rb +15 -15
- data/test/cases/json_test_sqlserver.rb +25 -25
- data/test/cases/lateral_test_sqlserver.rb +35 -0
- data/test/cases/migration_test_sqlserver.rb +67 -27
- data/test/cases/optimizer_hints_test_sqlserver.rb +72 -0
- data/test/cases/order_test_sqlserver.rb +53 -54
- data/test/cases/pessimistic_locking_test_sqlserver.rb +27 -33
- data/test/cases/rake_test_sqlserver.rb +33 -45
- data/test/cases/schema_dumper_test_sqlserver.rb +115 -109
- data/test/cases/schema_test_sqlserver.rb +20 -26
- data/test/cases/scratchpad_test_sqlserver.rb +4 -4
- data/test/cases/showplan_test_sqlserver.rb +28 -35
- data/test/cases/specific_schema_test_sqlserver.rb +68 -65
- data/test/cases/transaction_test_sqlserver.rb +18 -20
- data/test/cases/trigger_test_sqlserver.rb +14 -13
- data/test/cases/utils_test_sqlserver.rb +70 -70
- data/test/cases/uuid_test_sqlserver.rb +13 -14
- data/test/debug.rb +8 -6
- data/test/migrations/create_clients_and_change_column_null.rb +3 -1
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +4 -4
- data/test/models/sqlserver/booking.rb +3 -1
- data/test/models/sqlserver/customers_view.rb +3 -1
- data/test/models/sqlserver/datatype.rb +2 -0
- data/test/models/sqlserver/datatype_migration.rb +2 -0
- data/test/models/sqlserver/dollar_table_name.rb +3 -1
- data/test/models/sqlserver/edge_schema.rb +3 -3
- data/test/models/sqlserver/fk_has_fk.rb +3 -1
- data/test/models/sqlserver/fk_has_pk.rb +3 -1
- data/test/models/sqlserver/natural_pk_data.rb +4 -2
- data/test/models/sqlserver/natural_pk_int_data.rb +3 -1
- data/test/models/sqlserver/no_pk_data.rb +3 -1
- data/test/models/sqlserver/object_default.rb +3 -1
- data/test/models/sqlserver/quoted_table.rb +4 -2
- data/test/models/sqlserver/quoted_view_1.rb +3 -1
- data/test/models/sqlserver/quoted_view_2.rb +3 -1
- data/test/models/sqlserver/sst_memory.rb +3 -1
- data/test/models/sqlserver/string_default.rb +3 -1
- data/test/models/sqlserver/string_defaults_big_view.rb +3 -1
- data/test/models/sqlserver/string_defaults_view.rb +3 -1
- data/test/models/sqlserver/tinyint_pk.rb +3 -1
- data/test/models/sqlserver/trigger.rb +4 -2
- data/test/models/sqlserver/trigger_history.rb +3 -1
- data/test/models/sqlserver/upper.rb +3 -1
- data/test/models/sqlserver/uppered.rb +3 -1
- data/test/models/sqlserver/uuid.rb +3 -1
- data/test/schema/sqlserver_specific_schema.rb +31 -21
- data/test/support/coerceable_test_sqlserver.rb +15 -9
- data/test/support/connection_reflection.rb +3 -2
- data/test/support/core_ext/query_cache.rb +4 -1
- data/test/support/load_schema_sqlserver.rb +5 -5
- data/test/support/minitest_sqlserver.rb +3 -1
- data/test/support/paths_sqlserver.rb +11 -11
- data/test/support/rake_helpers.rb +13 -10
- data/test/support/sql_counter_sqlserver.rb +3 -4
- data/test/support/test_in_memory_oltp.rb +9 -7
- metadata +27 -12
- data/.travis.yml +0 -25
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe 'When table is dbo schema' do
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
class SchemaTestSQLServer < ActiveRecord::TestCase
|
|
6
|
+
describe "When table is dbo schema" do
|
|
7
|
+
it "find primary key for tables with odd schema" do
|
|
8
|
+
_(connection.primary_key("sst_natural_pk_data")).must_equal "legacy_id"
|
|
9
9
|
end
|
|
10
|
-
|
|
11
10
|
end
|
|
12
11
|
|
|
13
|
-
describe
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
assert connection.data_source_exists?(
|
|
17
|
-
assert connection.data_source_exists?('[test].[sst_schema_natural_id]')
|
|
12
|
+
describe "When table is in non-dbo schema" do
|
|
13
|
+
it "work with table exists" do
|
|
14
|
+
assert connection.data_source_exists?("test.sst_schema_natural_id")
|
|
15
|
+
assert connection.data_source_exists?("[test].[sst_schema_natural_id]")
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
it
|
|
21
|
-
_(connection.primary_key(
|
|
18
|
+
it "find primary key for tables with odd schema" do
|
|
19
|
+
_(connection.primary_key("test.sst_schema_natural_id")).must_equal "legacy_id"
|
|
22
20
|
end
|
|
23
21
|
|
|
24
22
|
it "have only one identity column" do
|
|
25
23
|
columns = connection.columns("test.sst_schema_identity")
|
|
26
24
|
assert_equal 2, columns.size
|
|
27
|
-
assert_equal 1, columns.select{ |c| c.is_identity? }.size
|
|
25
|
+
assert_equal 1, columns.select { |c| c.is_identity? }.size
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
it "read only column properties for table in specific schema" do
|
|
@@ -34,21 +32,17 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
|
|
|
34
32
|
assert_equal 7, test_columns.size
|
|
35
33
|
assert_equal 2, dbo_columns.size
|
|
36
34
|
assert_equal 2, columns.size
|
|
37
|
-
assert_equal 1, test_columns.select{ |c| c.is_identity? }.size
|
|
38
|
-
assert_equal 1, dbo_columns.select{ |c| c.is_identity? }.size
|
|
39
|
-
assert_equal 1, columns.select{ |c| c.is_identity? }.size
|
|
35
|
+
assert_equal 1, test_columns.select { |c| c.is_identity? }.size
|
|
36
|
+
assert_equal 1, dbo_columns.select { |c| c.is_identity? }.size
|
|
37
|
+
assert_equal 1, columns.select { |c| c.is_identity? }.size
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
it "return correct varchar and nvarchar column limit length when table is in non dbo schema" do
|
|
43
41
|
columns = connection.columns("test.sst_schema_columns")
|
|
44
|
-
assert_equal 255, columns.find {|c| c.name ==
|
|
45
|
-
assert_equal 1000, columns.find {|c| c.name ==
|
|
46
|
-
assert_equal 255, columns.find {|c| c.name ==
|
|
47
|
-
assert_equal 1000, columns.find {|c| c.name ==
|
|
42
|
+
assert_equal 255, columns.find { |c| c.name == "name" }.limit
|
|
43
|
+
assert_equal 1000, columns.find { |c| c.name == "description" }.limit
|
|
44
|
+
assert_equal 255, columns.find { |c| c.name == "n_name" }.limit
|
|
45
|
+
assert_equal 1000, columns.find { |c| c.name == "n_description" }.limit
|
|
48
46
|
end
|
|
49
|
-
|
|
50
47
|
end
|
|
51
|
-
|
|
52
|
-
|
|
53
48
|
end
|
|
54
|
-
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
class ScratchpadTestSQLServer < ActiveRecord::TestCase
|
|
6
|
+
it "helps debug things" do
|
|
6
7
|
end
|
|
7
|
-
|
|
8
8
|
end
|
|
@@ -1,69 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
require 'models/car'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
4
|
+
require "models/car"
|
|
5
5
|
|
|
6
|
+
class ShowplanTestSQLServer < ActiveRecord::TestCase
|
|
6
7
|
fixtures :cars
|
|
7
8
|
|
|
8
|
-
describe
|
|
9
|
-
|
|
10
|
-
it 'from simple statement' do
|
|
9
|
+
describe "Unprepare previously prepared SQL" do
|
|
10
|
+
it "from simple statement" do
|
|
11
11
|
plan = Car.where(id: 1).explain
|
|
12
12
|
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1"
|
|
13
|
-
_(plan).must_include "Clustered Index Seek",
|
|
13
|
+
_(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
it
|
|
16
|
+
it "from multiline statement" do
|
|
17
17
|
plan = Car.where("\n id = 1 \n").explain
|
|
18
18
|
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE (\n id = 1 \n)"
|
|
19
|
-
_(plan).must_include "Clustered Index Seek",
|
|
19
|
+
_(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
it
|
|
23
|
-
plan = Car.where(name:
|
|
24
|
-
_(plan).must_include "
|
|
25
|
-
_(plan).must_include "TOP EXPRESSION",
|
|
26
|
-
_(plan).must_include "Clustered Index Scan",
|
|
22
|
+
it "from prepared statement" do
|
|
23
|
+
plan = Car.where(name: ",").limit(1).explain
|
|
24
|
+
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[name]"
|
|
25
|
+
_(plan).must_include "TOP EXPRESSION", "make sure we do not showplan the sp_executesql"
|
|
26
|
+
_(plan).must_include "Clustered Index Scan", "make sure we do not showplan the sp_executesql"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
it
|
|
29
|
+
it "from array condition using index" do
|
|
30
30
|
plan = Car.where(id: [1, 2]).explain
|
|
31
|
-
_(plan).must_include "
|
|
32
|
-
_(plan).must_include "Clustered Index Seek",
|
|
31
|
+
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id] IN (1, 2)"
|
|
32
|
+
_(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
it
|
|
36
|
-
plan = Car.where(name: [
|
|
35
|
+
it "from array condition" do
|
|
36
|
+
plan = Car.where(name: ["honda", "zyke"]).explain
|
|
37
37
|
_(plan).must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name] IN (N'honda', N'zyke')"
|
|
38
|
-
_(plan).must_include "Clustered Index Scan",
|
|
38
|
+
_(plan).must_include "Clustered Index Scan", "make sure we do not showplan the sp_executesql"
|
|
39
39
|
end
|
|
40
|
-
|
|
41
40
|
end
|
|
42
41
|
|
|
43
|
-
describe
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
with_showplan_option('SHOWPLAN_TEXT') do
|
|
42
|
+
describe "With SHOWPLAN_TEXT option" do
|
|
43
|
+
it "use simple table printer" do
|
|
44
|
+
with_showplan_option("SHOWPLAN_TEXT") do
|
|
47
45
|
plan = Car.where(id: 1).explain
|
|
48
46
|
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id]"
|
|
49
|
-
_(plan).must_include "Clustered Index Seek",
|
|
47
|
+
_(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
|
|
50
48
|
end
|
|
51
49
|
end
|
|
52
|
-
|
|
53
50
|
end
|
|
54
51
|
|
|
55
|
-
describe
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
with_showplan_option('SHOWPLAN_XML') do
|
|
52
|
+
describe "With SHOWPLAN_XML option" do
|
|
53
|
+
it "show formatted xml" do
|
|
54
|
+
with_showplan_option("SHOWPLAN_XML") do
|
|
59
55
|
plan = Car.where(id: 1).explain
|
|
60
|
-
_(plan).must_include
|
|
56
|
+
_(plan).must_include "ShowPlanXML"
|
|
61
57
|
end
|
|
62
58
|
end
|
|
63
|
-
|
|
64
59
|
end
|
|
65
60
|
|
|
66
|
-
|
|
67
61
|
private
|
|
68
62
|
|
|
69
63
|
def with_showplan_option(option)
|
|
@@ -73,5 +67,4 @@ class ShowplanTestSQLServer < ActiveRecord::TestCase
|
|
|
73
67
|
ensure
|
|
74
68
|
ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = old_option
|
|
75
69
|
end
|
|
76
|
-
|
|
77
70
|
end
|
|
@@ -1,71 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
4
4
|
|
|
5
|
+
class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
|
|
5
6
|
after { SSTestEdgeSchema.delete_all }
|
|
6
7
|
|
|
7
|
-
it
|
|
8
|
+
it "handle dollar symbols" do
|
|
8
9
|
SSTestDollarTableName.create!
|
|
9
10
|
SSTestDollarTableName.limit(20).offset(1)
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
it
|
|
13
|
-
obj = SSTestTinyintPk.create! name:
|
|
14
|
-
_([
|
|
13
|
+
it "models can use tinyint pk tables" do
|
|
14
|
+
obj = SSTestTinyintPk.create! name: "1"
|
|
15
|
+
_(["Fixnum", "Integer"]).must_include obj.id.class.name
|
|
15
16
|
_(SSTestTinyintPk.find(obj.id)).must_equal obj
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
it
|
|
19
|
+
it "be able to complex count tables with no primary key" do
|
|
19
20
|
SSTestNoPkData.delete_all
|
|
20
21
|
10.times { |n| SSTestNoPkData.create! name: "Test#{n}" }
|
|
21
|
-
assert_equal 1, SSTestNoPkData.where(name:
|
|
22
|
+
assert_equal 1, SSTestNoPkData.where(name: "Test5").count
|
|
22
23
|
end
|
|
23
24
|
|
|
24
|
-
it
|
|
25
|
-
|
|
25
|
+
it "quote table names properly even when they are views" do
|
|
26
|
+
SSTestQuotedTable.create!
|
|
26
27
|
assert_nothing_raised { assert SSTestQuotedTable.first }
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
SSTestQuotedTableUser.create!
|
|
28
30
|
assert_nothing_raised { assert SSTestQuotedTableUser.first }
|
|
29
|
-
|
|
31
|
+
|
|
32
|
+
SSTestQuotedView1.create!
|
|
30
33
|
assert_nothing_raised { assert SSTestQuotedView1.first }
|
|
31
|
-
|
|
34
|
+
|
|
35
|
+
SSTestQuotedView2.create!
|
|
32
36
|
assert_nothing_raised { assert SSTestQuotedView2.first }
|
|
33
37
|
end
|
|
34
38
|
|
|
35
|
-
it
|
|
39
|
+
it "cope with multi line defaults" do
|
|
36
40
|
default = SSTestStringDefault.new
|
|
37
41
|
assert_equal "Some long default with a\nnew line.", default.string_with_multiline_default
|
|
38
42
|
end
|
|
39
43
|
|
|
40
|
-
it
|
|
44
|
+
it "default strings before save" do
|
|
41
45
|
default = SSTestStringDefault.new
|
|
42
46
|
assert_nil default.string_with_null_default
|
|
43
|
-
assert_equal
|
|
44
|
-
assert_equal
|
|
45
|
-
assert_equal
|
|
46
|
-
assert_equal
|
|
47
|
-
assert_equal
|
|
47
|
+
assert_equal "null", default.string_with_pretend_null_one
|
|
48
|
+
assert_equal "(null)", default.string_with_pretend_null_two
|
|
49
|
+
assert_equal "NULL", default.string_with_pretend_null_three
|
|
50
|
+
assert_equal "(NULL)", default.string_with_pretend_null_four
|
|
51
|
+
assert_equal "(3)", default.string_with_pretend_paren_three
|
|
48
52
|
end
|
|
49
53
|
|
|
50
|
-
it
|
|
54
|
+
it "default strings after save" do
|
|
51
55
|
default = SSTestStringDefault.create
|
|
52
56
|
assert_nil default.string_with_null_default
|
|
53
|
-
assert_equal
|
|
54
|
-
assert_equal
|
|
55
|
-
assert_equal
|
|
56
|
-
assert_equal
|
|
57
|
+
assert_equal "null", default.string_with_pretend_null_one
|
|
58
|
+
assert_equal "(null)", default.string_with_pretend_null_two
|
|
59
|
+
assert_equal "NULL", default.string_with_pretend_null_three
|
|
60
|
+
assert_equal "(NULL)", default.string_with_pretend_null_four
|
|
57
61
|
end
|
|
58
62
|
|
|
59
|
-
it
|
|
60
|
-
obj = SSTestObjectDefault.create! name:
|
|
61
|
-
_(obj.date).must_be_nil
|
|
63
|
+
it "default objects work" do
|
|
64
|
+
obj = SSTestObjectDefault.create! name: "MetaSkills"
|
|
65
|
+
_(obj.date).must_be_nil "since this is set on insert"
|
|
62
66
|
_(obj.reload.date).must_be_instance_of Date
|
|
63
67
|
end
|
|
64
68
|
|
|
65
|
-
it
|
|
66
|
-
_(SSTestBooking.columns_hash[
|
|
67
|
-
_(SSTestBooking.columns_hash[
|
|
68
|
-
obj1 = SSTestBooking.new name:
|
|
69
|
+
it "allows datetime2 as timestamps" do
|
|
70
|
+
_(SSTestBooking.columns_hash["created_at"].sql_type).must_equal "datetime2(7)"
|
|
71
|
+
_(SSTestBooking.columns_hash["updated_at"].sql_type).must_equal "datetime2(7)"
|
|
72
|
+
obj1 = SSTestBooking.new name: "test1"
|
|
69
73
|
obj1.save!
|
|
70
74
|
_(obj1.created_at).must_be_instance_of Time
|
|
71
75
|
_(obj1.updated_at).must_be_instance_of Time
|
|
@@ -73,35 +77,35 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
|
|
|
73
77
|
|
|
74
78
|
# Natural primary keys.
|
|
75
79
|
|
|
76
|
-
it
|
|
77
|
-
record = SSTestNaturalPkData.new name:
|
|
78
|
-
record.id =
|
|
80
|
+
it "work with identity inserts" do
|
|
81
|
+
record = SSTestNaturalPkData.new name: "Test", description: "Natural identity inserts."
|
|
82
|
+
record.id = "12345ABCDE"
|
|
79
83
|
assert record.save
|
|
80
|
-
assert_equal
|
|
84
|
+
assert_equal "12345ABCDE", record.reload.id
|
|
81
85
|
end
|
|
82
86
|
|
|
83
|
-
it
|
|
84
|
-
record = SSTestNaturalPkIntData.new name:
|
|
87
|
+
it "work with identity inserts when the key is an int" do
|
|
88
|
+
record = SSTestNaturalPkIntData.new name: "Test", description: "Natural identity inserts."
|
|
85
89
|
record.id = 12
|
|
86
90
|
assert record.save
|
|
87
91
|
assert_equal 12, record.reload.id
|
|
88
92
|
end
|
|
89
93
|
|
|
90
|
-
it
|
|
94
|
+
it "use primary key for row table order in pagination sql" do
|
|
91
95
|
sql = /ORDER BY \[sst_natural_pk_data\]\.\[legacy_id\] ASC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY/
|
|
92
96
|
assert_sql(sql) { SSTestNaturalPkData.limit(5).offset(5).load }
|
|
93
97
|
end
|
|
94
98
|
|
|
95
99
|
# Special quoted column
|
|
96
100
|
|
|
97
|
-
it
|
|
101
|
+
it "work as normal" do
|
|
98
102
|
SSTestEdgeSchema.delete_all
|
|
99
|
-
r = SSTestEdgeSchema.create!
|
|
100
|
-
assert SSTestEdgeSchema.columns_hash[
|
|
101
|
-
assert_equal r, SSTestEdgeSchema.where(
|
|
103
|
+
r = SSTestEdgeSchema.create! "crazy]]quote" => "crazyqoute"
|
|
104
|
+
assert SSTestEdgeSchema.columns_hash["crazy]]quote"]
|
|
105
|
+
assert_equal r, SSTestEdgeSchema.where("crazy]]quote" => "crazyqoute").first
|
|
102
106
|
end
|
|
103
107
|
|
|
104
|
-
it
|
|
108
|
+
it "various methods to bypass national quoted columns for any column, but primarily useful for char/varchar" do
|
|
105
109
|
value = Class.new do
|
|
106
110
|
def quoted_id
|
|
107
111
|
"'T'"
|
|
@@ -113,14 +117,14 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
|
|
|
113
117
|
# Using our custom char type data.
|
|
114
118
|
type = ActiveRecord::Type::SQLServer::Char
|
|
115
119
|
data = ActiveRecord::Type::SQLServer::Data
|
|
116
|
-
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: data.new(
|
|
117
|
-
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: data.new(
|
|
120
|
+
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: data.new("T", type.new)).first }
|
|
121
|
+
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: data.new("T", type.new)).first }
|
|
118
122
|
# Taking care of everything.
|
|
119
|
-
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col:
|
|
120
|
-
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col:
|
|
123
|
+
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(char_col: "T").first }
|
|
124
|
+
assert_sql(/@0 = 'T'/) { SSTestDatatypeMigration.where(varchar_col: "T").first }
|
|
121
125
|
end
|
|
122
126
|
|
|
123
|
-
it
|
|
127
|
+
it "can update and hence properly quoted non-national char/varchar columns" do
|
|
124
128
|
o = SSTestDatatypeMigration.create!
|
|
125
129
|
o.varchar_col = "O'Reilly"
|
|
126
130
|
o.save!
|
|
@@ -132,28 +136,28 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
|
|
|
132
136
|
|
|
133
137
|
# With column names that have spaces
|
|
134
138
|
|
|
135
|
-
it
|
|
136
|
-
value =
|
|
139
|
+
it "create record using a custom attribute reader and be able to load it back in" do
|
|
140
|
+
value = "Saved value into a column that has a space in the name."
|
|
137
141
|
record = SSTestEdgeSchema.create! with_spaces: value
|
|
138
142
|
assert_equal value, SSTestEdgeSchema.find(record.id).with_spaces
|
|
139
143
|
end
|
|
140
144
|
|
|
141
145
|
# With description column
|
|
142
146
|
|
|
143
|
-
it
|
|
144
|
-
SSTestEdgeSchema.create! description:
|
|
145
|
-
SSTestEdgeSchema.create! description:
|
|
146
|
-
SSTestEdgeSchema.create! description:
|
|
147
|
-
assert_equal [
|
|
148
|
-
assert_equal [
|
|
149
|
-
assert_equal [
|
|
150
|
-
assert_equal [
|
|
151
|
-
assert_equal [
|
|
147
|
+
it "allow all sorts of ordering without adapter munging it up with special description column" do
|
|
148
|
+
SSTestEdgeSchema.create! description: "A"
|
|
149
|
+
SSTestEdgeSchema.create! description: "B"
|
|
150
|
+
SSTestEdgeSchema.create! description: "C"
|
|
151
|
+
assert_equal ["A", "B", "C"], SSTestEdgeSchema.order("description").map(&:description)
|
|
152
|
+
assert_equal ["A", "B", "C"], SSTestEdgeSchema.order("description asc").map(&:description)
|
|
153
|
+
assert_equal ["A", "B", "C"], SSTestEdgeSchema.order("description ASC").map(&:description)
|
|
154
|
+
assert_equal ["C", "B", "A"], SSTestEdgeSchema.order("description desc").map(&:description)
|
|
155
|
+
assert_equal ["C", "B", "A"], SSTestEdgeSchema.order("description DESC").map(&:description)
|
|
152
156
|
end
|
|
153
157
|
|
|
154
158
|
# For uniqueidentifier model helpers
|
|
155
159
|
|
|
156
|
-
it
|
|
160
|
+
it "returns a new id via connection newid_function" do
|
|
157
161
|
acceptable_uuid = ActiveRecord::ConnectionAdapters::SQLServer::Type::Uuid::ACCEPTABLE_UUID
|
|
158
162
|
db_uuid = ActiveRecord::Base.connection.newid_function
|
|
159
163
|
_(db_uuid).must_match(acceptable_uuid)
|
|
@@ -161,10 +165,9 @@ class SpecificSchemaTestSQLServer < ActiveRecord::TestCase
|
|
|
161
165
|
|
|
162
166
|
# with similar table definition in two schemas
|
|
163
167
|
|
|
164
|
-
it
|
|
168
|
+
it "returns the correct primary columns" do
|
|
165
169
|
connection = ActiveRecord::Base.connection
|
|
166
|
-
assert_equal
|
|
167
|
-
assert_equal
|
|
170
|
+
assert_equal "field_1", connection.columns("test.sst_schema_test_mulitple_schema").detect(&:is_primary?).name
|
|
171
|
+
assert_equal "field_2", connection.columns("test2.sst_schema_test_mulitple_schema").detect(&:is_primary?).name
|
|
168
172
|
end
|
|
169
|
-
|
|
170
173
|
end
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
#
|
|
2
|
-
require 'cases/helper_sqlserver'
|
|
3
|
-
require 'models/ship'
|
|
4
|
-
require 'models/developer'
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
4
|
+
require "models/ship"
|
|
5
|
+
require "models/developer"
|
|
7
6
|
|
|
7
|
+
class TransactionTestSQLServer < ActiveRecord::TestCase
|
|
8
8
|
self.use_transactional_tests = false
|
|
9
9
|
|
|
10
10
|
before { delete_ships }
|
|
11
11
|
|
|
12
|
-
it
|
|
12
|
+
it "allow ActiveRecord::Rollback to work in 1 transaction block" do
|
|
13
13
|
Ship.transaction do
|
|
14
|
-
Ship.create! name:
|
|
14
|
+
Ship.create! name: "Black Pearl"
|
|
15
15
|
raise ActiveRecord::Rollback
|
|
16
16
|
end
|
|
17
17
|
assert_no_ships
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
it
|
|
20
|
+
it "allow nested transactions to totally rollback" do
|
|
21
21
|
begin
|
|
22
22
|
Ship.transaction do
|
|
23
|
-
Ship.create! name:
|
|
23
|
+
Ship.create! name: "Black Pearl"
|
|
24
24
|
Ship.transaction do
|
|
25
|
-
Ship.create! name:
|
|
26
|
-
raise
|
|
25
|
+
Ship.create! name: "Flying Dutchman"
|
|
26
|
+
raise "HELL"
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
rescue Exception
|
|
29
|
+
rescue Exception
|
|
30
30
|
assert_no_ships
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
it
|
|
34
|
+
it "can use an isolation level and reverts back to starting isolation level" do
|
|
35
35
|
in_level = nil
|
|
36
36
|
begin_level = connection.user_options_isolation_level
|
|
37
37
|
_(begin_level).must_match %r{read committed}i
|
|
38
38
|
Ship.transaction(isolation: :serializable) do
|
|
39
|
-
Ship.create! name:
|
|
39
|
+
Ship.create! name: "Black Pearl"
|
|
40
40
|
in_level = connection.user_options_isolation_level
|
|
41
41
|
end
|
|
42
42
|
after_level = connection.user_options_isolation_level
|
|
@@ -44,7 +44,7 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
|
|
|
44
44
|
_(after_level).must_match %r{read committed}i
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
it
|
|
47
|
+
it "can use an isolation level and reverts back to starting isolation level under exceptions" do
|
|
48
48
|
_(connection.user_options_isolation_level).must_match %r{read committed}i
|
|
49
49
|
_(lambda {
|
|
50
50
|
Ship.transaction(isolation: :serializable) { Ship.create! }
|
|
@@ -52,7 +52,7 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
|
|
|
52
52
|
_(connection.user_options_isolation_level).must_match %r{read committed}i
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
describe
|
|
55
|
+
describe "when READ_COMMITTED_SNAPSHOT is set" do
|
|
56
56
|
before do
|
|
57
57
|
connection.execute "ALTER DATABASE [#{connection.current_database}] SET ALLOW_SNAPSHOT_ISOLATION ON"
|
|
58
58
|
connection.execute "ALTER DATABASE [#{connection.current_database}] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE"
|
|
@@ -63,11 +63,11 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
|
|
|
63
63
|
connection.execute "ALTER DATABASE [#{connection.current_database}] SET READ_COMMITTED_SNAPSHOT OFF WITH ROLLBACK IMMEDIATE"
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
it
|
|
66
|
+
it "should use READ COMMITTED as an isolation level" do
|
|
67
67
|
_(connection.user_options_isolation_level).must_match "read committed snapshot"
|
|
68
68
|
|
|
69
69
|
Ship.transaction(isolation: :serializable) do
|
|
70
|
-
Ship.create! name:
|
|
70
|
+
Ship.create! name: "Black Pearl"
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# We're actually testing that the isolation level was correctly reset to
|
|
@@ -77,7 +77,6 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
|
|
81
80
|
protected
|
|
82
81
|
|
|
83
82
|
def delete_ships
|
|
@@ -87,5 +86,4 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
|
|
|
87
86
|
def assert_no_ships
|
|
88
87
|
assert Ship.count.zero?, "Expected Ship to have no models but it did have:\n#{Ship.all.inspect}"
|
|
89
88
|
end
|
|
90
|
-
|
|
91
89
|
end
|