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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae90a6f8498d914a0cff5b47bf56fe4eacf67fa771b4f89b06fb3c97683cf6ec
|
4
|
+
data.tar.gz: 3bcba233d32f874bc4914886d257f32cb45b06eec83a395cec9d0d4876c59bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fda1468adae0fe9a8de40c33abbcd34c4364b441e3ea55724130c1a871999e2985e7c7183a03534c0361b8d89f7f150be17ca30f98a3d4ac1d36dbe956e8174
|
7
|
+
data.tar.gz: a893c81ab5b00204c9014aba27cab25bee3513001043e71132e00938534d7c0ca0b7ea1cd1b8b10b347c97ece39e29a30ebdfbf85ed748f983b159573f0e1836
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Max: 120
|
6
|
+
|
7
|
+
Naming/AccessorMethodName:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Naming/FileName:
|
11
|
+
Exclude:
|
12
|
+
- lib/activerecord-sqlserver-adapter.rb
|
13
|
+
|
14
|
+
Naming/MethodName:
|
15
|
+
IgnoredPatterns:
|
16
|
+
- visit_.*
|
17
|
+
- primary_Key_From_Table
|
18
|
+
- table_From_Statement
|
19
|
+
- distinct_One_As_One_Is_So_Not_Fetch
|
20
|
+
- make_Fetch_Possible_And_Deterministic
|
21
|
+
|
22
|
+
Naming/MethodParameterName:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Naming/PredicateName:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/StringLiterals:
|
29
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## v6.0.0.rc2
|
2
|
+
|
3
|
+
#### Fixed
|
4
|
+
|
5
|
+
- [#639](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/639) Primary key should be lowercase if schema forced to lowercase
|
6
|
+
- [#720](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/720) quoted_date doesn't work for Type::DateTime
|
7
|
+
|
8
|
+
#### Changed
|
9
|
+
|
10
|
+
- [#826](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/826) Rubocop: Enable Style/StringLiterals cop
|
11
|
+
- [#827](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/827) Rubocop: Enable Layout/EmptyLinesAroundClassBody cop
|
12
|
+
- [#828](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/828) Rubocop: Enable Layout/EmptyLines cop
|
13
|
+
- [#829](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/829) Rubocop: Enable Layout/Layout/EmptyLinesAround* cops
|
14
|
+
- [#830](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/830) Rubocop: Enable Layout/IndentationWidth and Layout/TrailingWhitespace cops
|
15
|
+
- [#831](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/831) Rubocop: Enable Spacing cops
|
16
|
+
- [#832](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/832) Rubocop: Enable Bundler cops
|
17
|
+
- [#833](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/833) Rubocop: Enable Layout/* cops
|
18
|
+
- [#834](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/834) Rubocop: Enable Lint/UselessAssignment cop
|
19
|
+
- [#835](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/835) Rubocop: Configure Naming cops
|
20
|
+
|
1
21
|
## v6.0.0.rc1
|
2
22
|
|
3
23
|
#### Fixed
|
data/Gemfile
CHANGED
@@ -21,8 +21,8 @@ else
|
|
21
21
|
require "yaml"
|
22
22
|
|
23
23
|
spec = eval(File.read("activerecord-sqlserver-adapter.gemspec"))
|
24
|
-
ver = spec.dependencies.detect{ |d|d.name == "activerecord" }.requirement.requirements.first.last.version
|
25
|
-
major, minor,
|
24
|
+
ver = spec.dependencies.detect { |d| d.name == "activerecord" }.requirement.requirements.first.last.version
|
25
|
+
major, minor, _tiny, pre = ver.split(".")
|
26
26
|
|
27
27
|
if pre
|
28
28
|
ver
|
@@ -32,7 +32,7 @@ else
|
|
32
32
|
http.use_ssl = true
|
33
33
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
34
34
|
YAML.load(http.request(Net::HTTP::Get.new(uri.request_uri)).body).find do |data|
|
35
|
-
a, b,
|
35
|
+
a, b, = data["number"].split(".")
|
36
36
|
!data["prerelease"] && major == a && (minor.nil? || minor == b)
|
37
37
|
end["number"]
|
38
38
|
end
|
@@ -40,6 +40,7 @@ else
|
|
40
40
|
gem "rails", github: "rails/rails", tag: "v#{version}"
|
41
41
|
end
|
42
42
|
|
43
|
+
# rubocop:disable Bundler/DuplicatedGem
|
43
44
|
group :tinytds do
|
44
45
|
if ENV["TINYTDS_SOURCE"]
|
45
46
|
gem "tiny_tds", path: ENV["TINYTDS_SOURCE"]
|
@@ -49,11 +50,12 @@ group :tinytds do
|
|
49
50
|
gem "tiny_tds"
|
50
51
|
end
|
51
52
|
end
|
53
|
+
# rubocop:enable Bundler/DuplicatedGem
|
52
54
|
|
53
55
|
group :development do
|
54
|
-
gem "pry-byebug", platform: [:mri, :mingw, :x64_mingw]
|
55
|
-
gem "mocha"
|
56
56
|
gem "minitest-spec-rails"
|
57
|
+
gem "mocha"
|
58
|
+
gem "pry-byebug", platform: [:mri, :mingw, :x64_mingw]
|
57
59
|
end
|
58
60
|
|
59
61
|
group :guard do
|
@@ -61,3 +63,7 @@ group :guard do
|
|
61
63
|
gem "guard-minitest"
|
62
64
|
gem "terminal-notifier-guard" if RbConfig::CONFIG["host_os"] =~ /darwin/
|
63
65
|
end
|
66
|
+
|
67
|
+
group :rubocop do
|
68
|
+
gem "rubocop", require: false
|
69
|
+
end
|
data/Guardfile
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
require_relative
|
3
|
+
require_relative "test/support/paths_sqlserver"
|
3
4
|
|
4
5
|
clearing :on
|
5
6
|
notification :terminal_notifier if defined?(TerminalNotifier)
|
6
7
|
ignore %r{debug\.log}
|
7
8
|
|
8
|
-
ar_lib = File.join ARTest::SQLServer.root_activerecord,
|
9
|
-
ar_test = File.join ARTest::SQLServer.root_activerecord,
|
9
|
+
ar_lib = File.join ARTest::SQLServer.root_activerecord, "lib"
|
10
|
+
ar_test = File.join ARTest::SQLServer.root_activerecord, "test"
|
10
11
|
|
11
12
|
guard :minitest, {
|
12
13
|
all_on_start: false,
|
13
14
|
autorun: false,
|
14
|
-
include: [
|
15
|
-
test_folders: [
|
15
|
+
include: ["lib", "test", ar_lib, ar_test],
|
16
|
+
test_folders: ["test"],
|
16
17
|
test_file_patterns: ["*_test.rb", "*_test_sqlserver.rb"]
|
17
18
|
} do
|
18
19
|
# Our project watchers.
|
19
|
-
if ENV[
|
20
|
-
ENV[
|
20
|
+
if ENV["TEST_FILES"]
|
21
|
+
ENV["TEST_FILES"].split(",").map(&:strip).each do |file|
|
21
22
|
watch(%r{.*}) { file }
|
22
23
|
end
|
23
24
|
else
|
24
25
|
watch(%r{^test/cases/\w+_test_sqlserver\.rb$})
|
25
26
|
watch(%r{^test/cases/coerced_tests\.rb$}) { "test/cases/coerced_tests.rb" }
|
26
27
|
watch(%r{^lib/active_record/connection_adapters/sqlserver/([^/]+)\.rb$}) { |m| "test/cases/#{m[1]}_test_sqlserver.rb" }
|
27
|
-
watch(%r{^test/cases/helper_sqlserver\.rb$}) {
|
28
|
+
watch(%r{^test/cases/helper_sqlserver\.rb$}) { "test" }
|
28
29
|
end
|
29
30
|
end
|
data/Rakefile
CHANGED
@@ -1,39 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require_relative
|
6
|
-
require_relative
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
require_relative "test/support/paths_sqlserver"
|
6
|
+
require_relative "test/support/rake_helpers"
|
7
7
|
|
8
|
-
task test: [
|
8
|
+
task test: ["test:dblib"]
|
9
9
|
task default: [:test]
|
10
10
|
|
11
11
|
namespace :test do
|
12
|
-
|
13
12
|
%w(dblib).each do |mode|
|
14
|
-
|
15
13
|
Rake::TestTask.new(mode) do |t|
|
16
14
|
t.libs = ARTest::SQLServer.test_load_paths
|
17
15
|
t.test_files = test_files
|
18
|
-
t.warning = !!ENV[
|
16
|
+
t.warning = !!ENV["WARNING"]
|
19
17
|
t.verbose = false
|
20
18
|
end
|
21
|
-
|
22
19
|
end
|
23
20
|
|
24
|
-
task
|
25
|
-
ENV[
|
21
|
+
task "dblib:env" do
|
22
|
+
ENV["ARCONN"] = "dblib"
|
26
23
|
end
|
27
|
-
|
28
24
|
end
|
29
25
|
|
30
|
-
task
|
26
|
+
task "test:dblib" => "test:dblib:env"
|
31
27
|
|
32
28
|
namespace :profile do
|
33
|
-
[
|
29
|
+
["dblib"].each do |mode|
|
34
30
|
namespace mode.to_sym do
|
35
|
-
Dir.glob(
|
36
|
-
profile_case = File.basename(test_file).sub(
|
31
|
+
Dir.glob("test/profile/*_profile_case.rb").sort.each do |test_file|
|
32
|
+
profile_case = File.basename(test_file).sub("_profile_case.rb", "")
|
37
33
|
Rake::TestTask.new(profile_case) do |t|
|
38
34
|
t.libs = ARTest::SQLServer.test_load_paths
|
39
35
|
t.test_files = [test_file]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
6.0.0.
|
1
|
+
6.0.0.rc2
|
@@ -17,9 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.description = "ActiveRecord SQL Server Adapter. SQL Server 2012 and upward."
|
18
18
|
|
19
19
|
spec.metadata = {
|
20
|
-
"bug_tracker_uri"
|
21
|
-
"changelog_uri"
|
22
|
-
"source_code_uri"
|
20
|
+
"bug_tracker_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues",
|
21
|
+
"changelog_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v#{version}/CHANGELOG.md",
|
22
|
+
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}",
|
23
23
|
}
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -5,11 +5,9 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module CoreExt
|
7
7
|
module ActiveRecord
|
8
|
-
|
9
8
|
extend ActiveSupport::Concern
|
10
9
|
|
11
10
|
module ClassMethods
|
12
|
-
|
13
11
|
def execute_procedure(proc_name, *variables)
|
14
12
|
if connection.respond_to?(:execute_procedure)
|
15
13
|
connection.execute_procedure(proc_name, *variables)
|
@@ -17,9 +15,7 @@ module ActiveRecord
|
|
17
15
|
[]
|
18
16
|
end
|
19
17
|
end
|
20
|
-
|
21
18
|
end
|
22
|
-
|
23
19
|
end
|
24
20
|
end
|
25
21
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "active_record/attribute_methods"
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
6
|
module ConnectionAdapters
|
7
7
|
module SQLServer
|
8
8
|
module CoreExt
|
9
9
|
module AttributeMethods
|
10
|
-
|
11
|
-
|
12
10
|
private
|
13
11
|
|
14
12
|
def attributes_for_update(attribute_names)
|
@@ -17,7 +15,6 @@ module ActiveRecord
|
|
17
15
|
column && column.respond_to?(:is_identity?) && column.is_identity?
|
18
16
|
end
|
19
17
|
end
|
20
|
-
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "active_record/relation"
|
4
|
+
require "active_record/version"
|
5
5
|
|
6
6
|
module ActiveRecord
|
7
7
|
module ConnectionAdapters
|
8
8
|
module SQLServer
|
9
9
|
module CoreExt
|
10
10
|
module Calculations
|
11
|
-
|
12
11
|
# Same as original except we don't perform PostgreSQL hack that removes ordering.
|
13
12
|
def calculate(operation, column_name)
|
14
13
|
if has_include?(column_name)
|
@@ -17,7 +16,7 @@ module ActiveRecord
|
|
17
16
|
if operation.to_s.downcase == "count"
|
18
17
|
unless distinct_value || distinct_select?(column_name || select_for_count)
|
19
18
|
relation.distinct!
|
20
|
-
relation.select_values = [
|
19
|
+
relation.select_values = [klass.primary_key || table[Arel.star]]
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -5,8 +5,7 @@ module ActiveRecord
|
|
5
5
|
module SQLServer
|
6
6
|
module CoreExt
|
7
7
|
module Explain
|
8
|
-
|
9
|
-
SQLSERVER_STATEMENT_PREFIX = 'EXEC sp_executesql '
|
8
|
+
SQLSERVER_STATEMENT_PREFIX = "EXEC sp_executesql "
|
10
9
|
SQLSERVER_STATEMENT_REGEXP = /N'(.+)', N'(.+)', (.+)/
|
11
10
|
|
12
11
|
def exec_explain(queries)
|
@@ -34,7 +33,6 @@ module ActiveRecord
|
|
34
33
|
|
35
34
|
executesql
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "active_record/relation"
|
4
|
+
require "active_record/version"
|
5
5
|
|
6
6
|
module ActiveRecord
|
7
7
|
module ConnectionAdapters
|
8
8
|
module SQLServer
|
9
9
|
module CoreExt
|
10
10
|
module FinderMethods
|
11
|
-
|
12
11
|
private
|
13
12
|
|
14
13
|
# Same as original except we order by values in distinct select if present.
|
@@ -1,14 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "active_record/relation"
|
4
|
+
require "active_record/version"
|
5
5
|
|
6
6
|
module ActiveRecord
|
7
7
|
module ConnectionAdapters
|
8
8
|
module SQLServer
|
9
9
|
module CoreExt
|
10
10
|
module QueryMethods
|
11
|
-
|
12
11
|
private
|
13
12
|
|
14
13
|
# Copy of original from Rails master.
|
@@ -25,7 +25,7 @@ module ActiveRecord
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def exec_query(sql, name =
|
28
|
+
def exec_query(sql, name = "SQL", binds = [], prepare: false)
|
29
29
|
if preventing_writes? && write_query?(sql)
|
30
30
|
raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
|
31
31
|
end
|
@@ -44,17 +44,17 @@ module ActiveRecord
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def exec_delete(sql, name, binds)
|
47
|
-
sql = sql.dup <<
|
47
|
+
sql = sql.dup << "; SELECT @@ROWCOUNT AS AffectedRows"
|
48
48
|
super(sql, name, binds).rows.first.first
|
49
49
|
end
|
50
50
|
|
51
51
|
def exec_update(sql, name, binds)
|
52
|
-
sql = sql.dup <<
|
52
|
+
sql = sql.dup << "; SELECT @@ROWCOUNT AS AffectedRows"
|
53
53
|
super(sql, name, binds).rows.first.first
|
54
54
|
end
|
55
55
|
|
56
56
|
def begin_db_transaction
|
57
|
-
do_execute
|
57
|
+
do_execute "BEGIN TRANSACTION"
|
58
58
|
end
|
59
59
|
|
60
60
|
def transaction_isolation_levels
|
@@ -71,11 +71,11 @@ module ActiveRecord
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def commit_db_transaction
|
74
|
-
do_execute
|
74
|
+
do_execute "COMMIT TRANSACTION"
|
75
75
|
end
|
76
76
|
|
77
77
|
def exec_rollback_db_transaction
|
78
|
-
do_execute
|
78
|
+
do_execute "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION"
|
79
79
|
end
|
80
80
|
|
81
81
|
include Savepoints
|
@@ -143,7 +143,7 @@ module ActiveRecord
|
|
143
143
|
sql = +"INSERT #{insert.into}"
|
144
144
|
|
145
145
|
if returning = insert.send(:insert_all).returning
|
146
|
-
sql << " OUTPUT " << returning.map {|column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
|
146
|
+
sql << " OUTPUT " << returning.map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
|
147
147
|
end
|
148
148
|
|
149
149
|
sql << " #{insert.values_list}"
|
@@ -159,9 +159,9 @@ module ActiveRecord
|
|
159
159
|
variables.first.map { |k, v| "@#{k} = #{quote(v)}" }
|
160
160
|
else
|
161
161
|
variables.map { |v| quote(v) }
|
162
|
-
end.join(
|
162
|
+
end.join(", ")
|
163
163
|
sql = "EXEC #{proc_name} #{vars}".strip
|
164
|
-
name =
|
164
|
+
name = "Execute Procedure"
|
165
165
|
log(sql, name) do
|
166
166
|
case @connection_options[:mode]
|
167
167
|
when :dblib
|
@@ -186,20 +186,22 @@ module ActiveRecord
|
|
186
186
|
|
187
187
|
def use_database(database = nil)
|
188
188
|
return if sqlserver_azure?
|
189
|
+
|
189
190
|
name = SQLServer::Utils.extract_identifiers(database || @connection_options[:database]).quoted
|
190
191
|
do_execute "USE #{name}" unless name.blank?
|
191
192
|
end
|
192
193
|
|
193
194
|
def user_options
|
194
195
|
return {} if sqlserver_azure?
|
195
|
-
|
196
|
+
|
197
|
+
rows = select_rows("DBCC USEROPTIONS WITH NO_INFOMSGS", "SCHEMA")
|
196
198
|
rows = rows.first if rows.size == 2 && rows.last.empty?
|
197
199
|
rows.reduce(HashWithIndifferentAccess.new) do |values, row|
|
198
200
|
if row.instance_of? Hash
|
199
|
-
set_option = row.values[0].gsub(/\s+/,
|
201
|
+
set_option = row.values[0].gsub(/\s+/, "_")
|
200
202
|
user_value = row.values[1]
|
201
|
-
elsif
|
202
|
-
set_option = row[0].gsub(/\s+/,
|
203
|
+
elsif row.instance_of? Array
|
204
|
+
set_option = row[0].gsub(/\s+/, "_")
|
203
205
|
user_value = row[1]
|
204
206
|
end
|
205
207
|
values[set_option] = user_value
|
@@ -209,9 +211,9 @@ module ActiveRecord
|
|
209
211
|
|
210
212
|
def user_options_dateformat
|
211
213
|
if sqlserver_azure?
|
212
|
-
select_value
|
214
|
+
select_value "SELECT [dateformat] FROM [sys].[syslanguages] WHERE [langid] = @@LANGID", "SCHEMA"
|
213
215
|
else
|
214
|
-
user_options[
|
216
|
+
user_options["dateformat"]
|
215
217
|
end
|
216
218
|
end
|
217
219
|
|
@@ -226,29 +228,28 @@ module ActiveRecord
|
|
226
228
|
WHEN 5 THEN 'SNAPSHOT' END AS [isolation_level]
|
227
229
|
FROM [sys].[dm_exec_sessions]
|
228
230
|
WHERE [session_id] = @@SPID).squish
|
229
|
-
select_value sql,
|
231
|
+
select_value sql, "SCHEMA"
|
230
232
|
else
|
231
|
-
user_options[
|
233
|
+
user_options["isolation_level"]
|
232
234
|
end
|
233
235
|
end
|
234
236
|
|
235
237
|
def user_options_language
|
236
238
|
if sqlserver_azure?
|
237
|
-
select_value
|
239
|
+
select_value "SELECT @@LANGUAGE AS [language]", "SCHEMA"
|
238
240
|
else
|
239
|
-
user_options[
|
241
|
+
user_options["language"]
|
240
242
|
end
|
241
243
|
end
|
242
244
|
|
243
245
|
def newid_function
|
244
|
-
select_value
|
246
|
+
select_value "SELECT NEWID()"
|
245
247
|
end
|
246
248
|
|
247
249
|
def newsequentialid_function
|
248
|
-
select_value
|
250
|
+
select_value "SELECT NEWSEQUENTIALID()"
|
249
251
|
end
|
250
252
|
|
251
|
-
|
252
253
|
protected
|
253
254
|
|
254
255
|
def sql_for_insert(sql, pk, binds)
|
@@ -263,7 +264,7 @@ module ActiveRecord
|
|
263
264
|
exclude_output_inserted = exclude_output_inserted_table_name?(table_name, sql)
|
264
265
|
|
265
266
|
if exclude_output_inserted
|
266
|
-
id_sql_type = exclude_output_inserted.is_a?(TrueClass) ?
|
267
|
+
id_sql_type = exclude_output_inserted.is_a?(TrueClass) ? "bigint" : exclude_output_inserted
|
267
268
|
<<~SQL.squish
|
268
269
|
DECLARE @ssaIdInsertTable table (#{quoted_pk} #{id_sql_type});
|
269
270
|
#{sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk} INTO @ssaIdInsertTable"}
|
@@ -288,7 +289,7 @@ module ActiveRecord
|
|
288
289
|
|
289
290
|
# === SQLServer Specific (Executing) ============================ #
|
290
291
|
|
291
|
-
def do_execute(sql, name =
|
292
|
+
def do_execute(sql, name = "SQL")
|
292
293
|
materialize_transactions
|
293
294
|
|
294
295
|
log(sql, name) { raw_connection_do(sql) }
|
@@ -316,11 +317,12 @@ module ActiveRecord
|
|
316
317
|
|
317
318
|
def sp_executesql_sql_type(attr)
|
318
319
|
return attr.type.sqlserver_type if attr.type.respond_to?(:sqlserver_type)
|
320
|
+
|
319
321
|
case value = attr.value_for_database
|
320
322
|
when Numeric
|
321
|
-
value > 2_147_483_647 ?
|
323
|
+
value > 2_147_483_647 ? "bigint".freeze : "int".freeze
|
322
324
|
else
|
323
|
-
|
325
|
+
"nvarchar(max)".freeze
|
324
326
|
end
|
325
327
|
end
|
326
328
|
|
@@ -335,14 +337,14 @@ module ActiveRecord
|
|
335
337
|
end
|
336
338
|
|
337
339
|
def sp_executesql_sql(sql, types, params, name)
|
338
|
-
if name ==
|
340
|
+
if name == "EXPLAIN"
|
339
341
|
params.each.with_index do |param, index|
|
340
342
|
substitute_at_finder = /(@#{index})(?=(?:[^']|'[^']*')*$)/ # Finds unquoted @n values.
|
341
343
|
sql = sql.sub substitute_at_finder, param.to_s
|
342
344
|
end
|
343
345
|
else
|
344
|
-
types = quote(types.join(
|
345
|
-
params = params.map.with_index{ |p, i| "@#{i} = #{p}" }.join(
|
346
|
+
types = quote(types.join(", "))
|
347
|
+
params = params.map.with_index { |p, i| "@#{i} = #{p}" }.join(", ") # Only p is needed, but with @i helps explain regexp.
|
346
348
|
sql = "EXEC sp_executesql #{quote(sql)}"
|
347
349
|
sql += ", #{types}, #{params}" unless params.empty?
|
348
350
|
end
|
@@ -357,7 +359,7 @@ module ActiveRecord
|
|
357
359
|
# TinyTDS returns false instead of raising an exception if connection fails.
|
358
360
|
# Getting around this by raising an exception ourselves while this PR
|
359
361
|
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
|
360
|
-
raise TinyTds::Error,
|
362
|
+
raise TinyTds::Error, "failed to execute statement" if result.is_a?(FalseClass)
|
361
363
|
|
362
364
|
result.do
|
363
365
|
end
|
@@ -377,8 +379,10 @@ module ActiveRecord
|
|
377
379
|
|
378
380
|
def exclude_output_inserted_table_name?(table_name, sql)
|
379
381
|
return false unless exclude_output_inserted_table_names?
|
382
|
+
|
380
383
|
table_name ||= get_table_name(sql)
|
381
384
|
return false unless table_name
|
385
|
+
|
382
386
|
self.class.exclude_output_inserted_table_names[table_name]
|
383
387
|
end
|
384
388
|
|
@@ -407,7 +411,7 @@ module ActiveRecord
|
|
407
411
|
|
408
412
|
# === SQLServer Specific (Selecting) ============================ #
|
409
413
|
|
410
|
-
def raw_select(sql, name =
|
414
|
+
def raw_select(sql, name = "SQL", binds = [], options = {})
|
411
415
|
log(sql, name, binds) { _raw_select(sql, options) }
|
412
416
|
end
|
413
417
|
|
@@ -455,7 +459,6 @@ module ActiveRecord
|
|
455
459
|
end
|
456
460
|
handle
|
457
461
|
end
|
458
|
-
|
459
462
|
end
|
460
463
|
end
|
461
464
|
end
|