activerecord-sqlserver-adapter 7.1.7 → 7.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/CHANGELOG.md +12 -0
- data/README.md +10 -9
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +3 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +1 -0
- data/lib/arel/visitors/sqlserver.rb +35 -3
- data/test/cases/coerced_tests.rb +41 -1
- data/test/cases/schema_test_sqlserver.rb +4 -0
- data/test/cases/view_test_sqlserver.rb +8 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c9a920a4f60419f9224af3015631bceb30eea4b70356e947f26f9c05feaff3a
|
4
|
+
data.tar.gz: '08182d688ca9aa20b42f4a42e29580335665f751d873fc1443d71e3d03a550bd'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f72132748467ea80ed8f364f32522cb0b59a678b2895875d485473328f017d34c39cf8d60fc916ee0fa1d1c0344f078d0ff30ec67caff38e978961d2eaf9c2c
|
7
|
+
data.tar.gz: cca704ba3fbda50765708251a1d2c3f081e0d2258505eac05d759bbe7455e4b81692e80d94a7f02e45c29d497624e3d285d41883e893a8af3451be18c4d99618
|
data/.github/workflows/ci.yml
CHANGED
@@ -5,7 +5,7 @@ on: [push, pull_request]
|
|
5
5
|
jobs:
|
6
6
|
test:
|
7
7
|
name: Run test suite
|
8
|
-
runs-on: ubuntu-latest
|
8
|
+
runs-on: ubuntu-20.04 # TODO: Change back to 'ubuntu-latest' when https://github.com/microsoft/mssql-docker/issues/899 resolved.
|
9
9
|
|
10
10
|
env:
|
11
11
|
COMPOSE_FILE: docker-compose.ci.yml
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## v7.1.9
|
2
|
+
|
3
|
+
#### Fixed
|
4
|
+
|
5
|
+
- [#1245](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1245) Allow INSERT statements with SELECT notation
|
6
|
+
|
7
|
+
## v7.1.8
|
8
|
+
|
9
|
+
#### Fixed
|
10
|
+
|
11
|
+
- [#1232](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1232) Enable identity insert on view's base table
|
12
|
+
|
1
13
|
## v7.1.7
|
2
14
|
|
3
15
|
#### Fixed
|
data/README.md
CHANGED
@@ -11,17 +11,18 @@ The SQL Server adapter for ActiveRecord using SQL Server 2012 or higher.
|
|
11
11
|
|
12
12
|
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 7.x version of the adapter is only for the latest 7.x version of Rails. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter that matches your Rails version. We also have stable branches for each major/minor release of ActiveRecord.
|
13
13
|
|
14
|
+
See [Rubygems](https://rubygems.org/gems/activerecord-sqlserver-adapter/versions) for the latest version of the adapter for each Rails release.
|
15
|
+
|
14
16
|
| Adapter Version | Rails Version | Support | Branch |
|
15
17
|
|-----------------|---------------|---------|--------------------------------------------------------------------------------------------------|
|
16
|
-
|
|
17
|
-
| `7.
|
18
|
-
| `
|
19
|
-
| `6.
|
20
|
-
| `
|
21
|
-
| `5.
|
22
|
-
| `
|
23
|
-
| `4.
|
24
|
-
| `4.1.8` | `4.1.x` | Ended | [4-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
|
18
|
+
| `7.1.x` | `7.1.x` | Active | [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-1-stable) |
|
19
|
+
| `7.0.x` | `7.0.x` | Ended | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
|
20
|
+
| `6.1.x` | `6.1.x` | Ended | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
|
21
|
+
| `6.0.x` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
|
22
|
+
| `5.2.x` | `5.2.x` | Ended | [5-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
|
23
|
+
| `5.1.x` | `5.1.x` | Ended | [5-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
|
24
|
+
| `4.2.x` | `4.2.x` | Ended | [4-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
|
25
|
+
| `4.1.x` | `4.1.x` | Ended | [4-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
|
25
26
|
|
26
27
|
For older versions, please check their stable branches.
|
27
28
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.1.
|
1
|
+
7.1.9
|
@@ -45,6 +45,9 @@ module ActiveRecord
|
|
45
45
|
log(sql, name, binds, async: async) do
|
46
46
|
with_raw_connection do |conn|
|
47
47
|
if id_insert_table_name = query_requires_identity_insert?(sql)
|
48
|
+
# If the table name is a view, we need to get the base table name for enabling identity insert.
|
49
|
+
id_insert_table_name = view_table_name(id_insert_table_name) if view_exists?(id_insert_table_name)
|
50
|
+
|
48
51
|
with_identity_insert_enabled(id_insert_table_name, conn) do
|
49
52
|
result = internal_exec_sql_query(sql, conn)
|
50
53
|
end
|
@@ -681,6 +681,7 @@ module ActiveRecord
|
|
681
681
|
s.split(/INSERT INTO/i)[1]
|
682
682
|
.split(/OUTPUT INSERTED/i)[0]
|
683
683
|
.split(/(DEFAULT)?\s+VALUES/i)[0]
|
684
|
+
.split(/\bSELECT\b(?![^\[]*\])/i)[0]
|
684
685
|
.match(/\s*([^(]*)/i)[0]
|
685
686
|
elsif s.match?(/^\s*UPDATE\s+.*/i)
|
686
687
|
s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
|
@@ -30,10 +30,42 @@ module Arel
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def visit_Arel_Nodes_UpdateStatement(o, collector)
|
33
|
-
if
|
34
|
-
o
|
33
|
+
if has_join_and_composite_primary_key?(o)
|
34
|
+
update_statement_using_join(o, collector)
|
35
|
+
else
|
36
|
+
o.limit = Nodes::Limit.new(9_223_372_036_854_775_807) if o.orders.any? && o.limit.nil?
|
37
|
+
|
38
|
+
super
|
35
39
|
end
|
36
|
-
|
40
|
+
end
|
41
|
+
|
42
|
+
def visit_Arel_Nodes_DeleteStatement(o, collector)
|
43
|
+
if has_join_and_composite_primary_key?(o)
|
44
|
+
delete_statement_using_join(o, collector)
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_join_and_composite_primary_key?(o)
|
51
|
+
has_join_sources?(o) && o.relation.left.instance_variable_get(:@klass).composite_primary_key?
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete_statement_using_join(o, collector)
|
55
|
+
collector << "DELETE "
|
56
|
+
visit o.relation.left, collector
|
57
|
+
collector << " FROM "
|
58
|
+
visit o.relation, collector
|
59
|
+
collect_nodes_for o.wheres, collector, " WHERE ", " AND "
|
60
|
+
end
|
61
|
+
|
62
|
+
def update_statement_using_join(o, collector)
|
63
|
+
collector << "UPDATE "
|
64
|
+
visit o.relation.left, collector
|
65
|
+
collect_nodes_for o.values, collector, " SET "
|
66
|
+
collector << " FROM "
|
67
|
+
visit o.relation, collector
|
68
|
+
collect_nodes_for o.wheres, collector, " WHERE ", " AND "
|
37
69
|
end
|
38
70
|
|
39
71
|
def visit_Arel_Nodes_Lock(o, collector)
|
data/test/cases/coerced_tests.rb
CHANGED
@@ -702,7 +702,6 @@ module ActiveRecord
|
|
702
702
|
ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate
|
703
703
|
assert connection.table_exists?(long_table_name[0...-1])
|
704
704
|
assert_not connection.table_exists?(:more_testings)
|
705
|
-
assert connection.table_exists?(long_table_name[0...-1])
|
706
705
|
ensure
|
707
706
|
connection.drop_table(:more_testings) rescue nil
|
708
707
|
connection.drop_table(long_table_name[0...-1]) rescue nil
|
@@ -727,6 +726,28 @@ module ActiveRecord
|
|
727
726
|
assert_match(/Index name \'#{long_index_name}\' on table \'testings\' is too long/i, error.message)
|
728
727
|
end
|
729
728
|
|
729
|
+
# SQL Server truncates long table names when renaming.
|
730
|
+
coerce_tests! :test_rename_table_errors_on_too_long_index_name_7_0
|
731
|
+
def test_rename_table_errors_on_too_long_index_name_7_0_coerced
|
732
|
+
long_table_name = "a" * (connection.table_name_length + 1)
|
733
|
+
|
734
|
+
migration = Class.new(ActiveRecord::Migration[7.0]) {
|
735
|
+
def migrate(x)
|
736
|
+
add_index :testings, :foo
|
737
|
+
long_table_name = "a" * (connection.table_name_length + 1)
|
738
|
+
rename_table :testings, long_table_name
|
739
|
+
end
|
740
|
+
}.new
|
741
|
+
|
742
|
+
ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate
|
743
|
+
|
744
|
+
assert_not connection.table_exists?(:testings)
|
745
|
+
assert connection.table_exists?(long_table_name[0...-1])
|
746
|
+
assert connection.index_exists?(long_table_name[0...-1], :foo)
|
747
|
+
ensure
|
748
|
+
connection.drop_table(long_table_name[0...-1], if_exists: true)
|
749
|
+
end
|
750
|
+
|
730
751
|
# SQL Server has a different maximum index name length.
|
731
752
|
coerce_tests! :test_create_table_add_index_errors_on_too_long_name_7_0
|
732
753
|
def test_create_table_add_index_errors_on_too_long_name_7_0_coerced
|
@@ -2484,6 +2505,25 @@ class QueryLogsTest < ActiveRecord::TestCase
|
|
2484
2505
|
end
|
2485
2506
|
end
|
2486
2507
|
|
2508
|
+
# SQL requires double single-quotes.
|
2509
|
+
coerce_tests! :test_sqlcommenter_format_allows_string_keys
|
2510
|
+
def test_sqlcommenter_format_allows_string_keys_coerced
|
2511
|
+
ActiveRecord::QueryLogs.update_formatter(:sqlcommenter)
|
2512
|
+
|
2513
|
+
ActiveRecord::QueryLogs.tags = [
|
2514
|
+
:application,
|
2515
|
+
{
|
2516
|
+
"string" => "value",
|
2517
|
+
tracestate: "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7",
|
2518
|
+
custom_proc: -> { "Joe's Shack" }
|
2519
|
+
},
|
2520
|
+
]
|
2521
|
+
|
2522
|
+
assert_sql(%r{custom_proc=''Joe%27s%20Shack'',string=''value'',tracestate=''congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7''\*/}) do
|
2523
|
+
Dashboard.first
|
2524
|
+
end
|
2525
|
+
end
|
2526
|
+
|
2487
2527
|
# Invalid character encoding causes `ActiveRecord::StatementInvalid` error similar to Postgres.
|
2488
2528
|
coerce_tests! :test_invalid_encoding_query
|
2489
2529
|
def test_invalid_encoding_query_coerced
|
@@ -96,6 +96,10 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
|
|
96
96
|
it do
|
97
97
|
assert_equal "[test].[aliens]", connection.send(:get_raw_table_name, "EXEC sp_executesql N'INSERT INTO [test].[aliens] ([name]) OUTPUT INSERTED.[id] VALUES (@0)', N'@0 varchar(255)', @0 = 'Trisolarans'")
|
98
98
|
end
|
99
|
+
|
100
|
+
it do
|
101
|
+
assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "INSERT INTO [with].[select notation] SELECT * FROM [table_name]")
|
102
|
+
end
|
99
103
|
end
|
100
104
|
end
|
101
105
|
end
|
@@ -47,4 +47,12 @@ class ViewTestSQLServer < ActiveRecord::TestCase
|
|
47
47
|
assert_equal 1, klass.count
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe 'identity insert' do
|
52
|
+
it "identity insert works with views" do
|
53
|
+
assert_difference("SSTestCustomersView.count", 1) do
|
54
|
+
SSTestCustomersView.create!(id: 5, name: "Bob")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
50
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sqlserver-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2024-
|
18
|
+
date: 2024-11-10 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -240,8 +240,8 @@ licenses:
|
|
240
240
|
- MIT
|
241
241
|
metadata:
|
242
242
|
bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
|
243
|
-
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.
|
244
|
-
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.
|
243
|
+
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.9/CHANGELOG.md
|
244
|
+
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.9
|
245
245
|
post_install_message:
|
246
246
|
rdoc_options: []
|
247
247
|
require_paths:
|
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
257
|
- !ruby/object:Gem::Version
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
|
-
rubygems_version: 3.
|
260
|
+
rubygems_version: 3.5.21
|
261
261
|
signing_key:
|
262
262
|
specification_version: 4
|
263
263
|
summary: ActiveRecord SQL Server Adapter.
|