activerecord-sqlserver-adapter 7.1.7 → 7.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb26ce0a56d756f8e9ba1d571ab3f3b6ce092ac3c86f8b37bce56942ec96c485
4
- data.tar.gz: efa5adca77b15a3c5b25c216b1b63d311a1fbfbc5ab79186d94f1b4f9a6ecedb
3
+ metadata.gz: dac0412f21213482d15ff47e53332fe825939a1c4e1d9526884b2a4c91a93d7d
4
+ data.tar.gz: c86cf7d138d27def9534f715c421b029370649343985b4e9d5d16e1c9953ae03
5
5
  SHA512:
6
- metadata.gz: 6bfc66070966a026f6f1b42bf1c87e48ad9e0d044ce01755eeddbcbc71f2b5cabd8cd395dc9ebfa0aa1e92c5b8f4c524ead92d1abf017b907de774f224c0c02a
7
- data.tar.gz: 9ebcf4c64077e0fdfac80b7f5ca6fc5b6218251f378dd6f61c3fcbfd48e4196a93fc09a5de87048834f1e96f3b839ddd2e0ec61457da081bf3f20fd5d5fed08c
6
+ metadata.gz: b2ef1d7310bea2d0e1bf6feb84a4dd9124898cb80ec83b9f4c30e7f94ce9e4a3220f57285a5f3d71a2dc48706a906edb17a39ad099367b871d52fe5783dc6225
7
+ data.tar.gz: f510e15d47aaadd47a5ceeb2b89d0becbc91758ef4b4383caaef940a8ad29a462cd737a0f967186c7cafbc5c57d2277c46b8c0332f32e43c64461957b147cb3e
@@ -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,9 @@
1
+ ## v7.1.8
2
+
3
+ #### Fixed
4
+
5
+ - [#1232](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1232) Enable identity insert on view's base table
6
+
1
7
  ## v7.1.7
2
8
 
3
9
  #### 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
- | Unreleased | `7.2.x` | In Development | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
17
- | `7.1.7` | `7.1.x` | Active | [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-1-stable) |
18
- | `7.0.7` | `7.0.x` | Active | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
19
- | `6.1.3.0` | `6.1.x` | Active | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
20
- | `6.0.3` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
21
- | `5.2.1` | `5.2.x` | Ended | [5-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
22
- | `5.1.6` | `5.1.x` | Ended | [5-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
23
- | `4.2.18` | `4.2.x` | Ended | [4-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
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.7
1
+ 7.1.8
@@ -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
@@ -30,10 +30,42 @@ module Arel
30
30
  end
31
31
 
32
32
  def visit_Arel_Nodes_UpdateStatement(o, collector)
33
- if o.orders.any? && o.limit.nil?
34
- o.limit = Nodes::Limit.new(9_223_372_036_854_775_807)
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
- super
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)
@@ -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
@@ -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.7
4
+ version: 7.1.8
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-08-01 00:00:00.000000000 Z
18
+ date: 2024-10-02 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.7/CHANGELOG.md
244
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.7
243
+ changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.8/CHANGELOG.md
244
+ source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.8
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.4.22
260
+ rubygems_version: 3.5.17
261
261
  signing_key:
262
262
  specification_version: 4
263
263
  summary: ActiveRecord SQL Server Adapter.