activerecord-sqlserver-adapter 8.1.4 → 8.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b449fb9569a0dcfc91cc7e0109a29a145dc0c11b8488a3eb486650fa037eb2ad
4
- data.tar.gz: ca39fe0127a4ab8e507b49c5a49f59ae02f193d6d54ae3f0d2e9f7731c6f4b08
3
+ metadata.gz: 8103d328f1d51f08dde31a8bbced71a012fc358b184b4aaa21be24514f6111fd
4
+ data.tar.gz: d323e094a08f832485ef779a7d6cf6744097f3b85699d10a66341773f0245f61
5
5
  SHA512:
6
- metadata.gz: d5a25f54332ba7e594ceef724da573ef3add3820e7f7de4dcc3a59622c77b5a5978a433efa42894f9467d8940024e11345022d556522a2000289a5f2046cd012
7
- data.tar.gz: ed563ea7651fb586b42c3d59f17d8459b73245ebf014b9121a85baff1584a405a4ec72e8a1a005cbf57c9e0fa84f8a5c8ad4b20c3d451a5490e58b19f34af394
6
+ metadata.gz: a28e4de8a7beff44262ddf174ca05d677e64885edaed6fdf117faabd2b0a581bd5eeede241679b9f8188bfc0e68311e58f7b87afccc9ab4f6c9346e2fae93a1a
7
+ data.tar.gz: 3a6a07d9a9ef6c2ee7a01fe64dcebc343d50665ef45afb3b028ce8251d78ec1ec5205d3917ccb9b55ef106178ac0bfcda1a8afba176ca62ef97441fc39362688
@@ -13,6 +13,10 @@ RUN apt-get -y install libc6-dev \
13
13
  && make \
14
14
  && make install
15
15
 
16
+ # Fix Yarn key (https://classic.yarnpkg.com/en/docs/install#debian-stable)
17
+ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn-archive-keyring.gpg > /dev/null
18
+ RUN echo "deb [signed-by=/etc/apt/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
19
+
16
20
  # Install the SQL Server command-line tools
17
21
  RUN curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc \
18
22
  && curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list \
@@ -0,0 +1,6 @@
1
+ # Auto generated files with errors to ignore.
2
+ # Remove from this list as you refactor files.
3
+ ---
4
+ ignore:
5
+ - test/cases/migration_test_sqlserver.rb:
6
+ - Style/ReverseFind
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## v8.1.5
2
+
3
+ #### Fixed
4
+
5
+ - [#1424](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1424) Fix table name parsing for `INSERT INTO <table> WITH (<hints>)`.
6
+ - [#1430](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1430) Fix escaping of closing brackets inside identifiers.
7
+
1
8
  ## v8.1.4
2
9
 
3
10
  #### Fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.1.4
1
+ 8.1.5
@@ -478,7 +478,7 @@ module ActiveRecord
478
478
  id_column = identity_columns(raw_table_name).first
479
479
 
480
480
  if id_column && (
481
- sql =~ /^\s*(INSERT|EXEC sp_executesql N'INSERT)[^(]+\([^)]*\b(#{id_column.name})\b,?[^)]*\)/i ||
481
+ sql =~ /^\s*(INSERT|EXEC sp_executesql N'INSERT)[^(]+(?:WITH\s*\([^)]*\)\s*)?\([^)]*\b(#{id_column.name})\b,?[^)]*\)/i ||
482
482
  sql =~ /^\s*MERGE INTO.+THEN INSERT \([^)]*\b(#{id_column.name})\b,?[^)]*\)/im
483
483
  )
484
484
  SQLServer::Utils.extract_identifiers(raw_table_name).quoted
@@ -730,6 +730,7 @@ module ActiveRecord
730
730
  .split(/OUTPUT INSERTED/i)[0]
731
731
  .split(/(DEFAULT)?\s+VALUES/i)[0]
732
732
  .split(/\bSELECT\b(?![^\[]*\])/i)[0]
733
+ .split(/\s+WITH\s*\(/i)[0] # Strip table hints (eg: "INSERT INTO books WITH (TABLOCK) (title)")
733
734
  .match(/\s*([^(]*)/i)[0]
734
735
  elsif s.match?(/^\s*UPDATE\s+.*/i)
735
736
  s.match(/UPDATE\s+([^(\s]+)\s*/i)[1]
@@ -12,6 +12,8 @@ module ActiveRecord
12
12
  UNQUOTED_SCANNER = /\]?\./
13
13
  QUOTED_SCANNER = /\A\[.*?\]\./
14
14
  QUOTED_CHECKER = /\A\[/
15
+ QUOTED_IDENTIFIER = /\[(?:[^\]]|\]\])*\]/
16
+ QUOTED_IDENTIFIERS = /\A#{QUOTED_IDENTIFIER}(?:\.+#{QUOTED_IDENTIFIER})*\z/
15
17
 
16
18
  attr_reader :server, :database, :schema, :object
17
19
  attr_reader :raw_name
@@ -113,7 +115,7 @@ module ActiveRecord
113
115
  end
114
116
 
115
117
  def quote(part)
116
- /\A\[.*\]\z/.match?(part) ? part : "[#{part.to_s.gsub("]", "]]")}]"
118
+ QUOTED_IDENTIFIERS.match?(part) ? part : "[#{part.to_s.gsub("]", "]]")}]"
117
119
  end
118
120
 
119
121
  def unquote(part)
@@ -103,6 +103,14 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
103
103
  assert_equal "customers", connection.send(:get_table_name, basic_select_sql)
104
104
  end
105
105
 
106
+ it "execute INSERT statements with table hints" do
107
+ assert_difference -> { connection.select_value("SELECT COUNT(*) FROM [funny_jokes]") }, 2 do
108
+ connection.execute("INSERT INTO [funny_jokes] WITH (TABLOCK) ([name]) VALUES ('Knock knock')")
109
+ connection.execute("INSERT INTO [funny_jokes] WITH (TABLOCK) ([id], [name]) VALUES (420, 'Knock knock')")
110
+ end
111
+ assert_equal "Knock knock", connection.select_value("SELECT [name] FROM [funny_jokes] WHERE [id] = 420")
112
+ end
113
+
106
114
  it "test bad connection" do
107
115
  assert_raise ActiveRecord::NoDatabaseError do
108
116
  db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
@@ -2505,6 +2505,16 @@ class FieldOrderedValuesTest < ActiveRecord::TestCase
2505
2505
  Book.where(author_id: nil, name: nil).delete_all
2506
2506
  Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
2507
2507
  end
2508
+
2509
+ # coerce_tests! :test_in_order_of_with_column_from_cte_serializes_custom_attribute_values
2510
+ # def test_in_order_of_with_column_from_cte_serializes_custom_attribute_values_coerced
2511
+ # connection.remove_index(:books, column: [:author_id, :name])
2512
+ #
2513
+ # original_test_in_order_of_with_column_from_cte_serializes_custom_attribute_values
2514
+ # ensure
2515
+ # Book.where(author_id: nil, name: nil).delete_all
2516
+ # Book.lease_connection.add_index(:books, [:author_id, :name], unique: true)
2517
+ # end
2508
2518
  end
2509
2519
 
2510
2520
  class QueryLogsTest < ActiveRecord::TestCase
@@ -2910,3 +2920,39 @@ class ActiveRecord::Encryption::EncryptableFixtureTest < ActiveRecord::Encryptio
2910
2920
  send(:"original_fixtures for json columns get encrypted automatically")
2911
2921
  end
2912
2922
  end
2923
+
2924
+ # class ActiveRecord::LoadAsyncMultiThreadPoolExecutorTest < ActiveRecord::TestCase
2925
+ # # The SQL Server `AVG()` function for a list of integers returns an integer (not a decimal).
2926
+ # coerce_tests! :test_async_queries_from_transaction_run_synchronously
2927
+ # def test_async_queries_from_transaction_run_synchronously_coerced
2928
+ # events = []
2929
+ # Post.transaction do
2930
+ # Post.where(author_id: 1).update_all(title: "In Transaction")
2931
+ # scope = Post.where(title: "In Transaction")
2932
+ # expected_ids = scope.order(:id).ids
2933
+ #
2934
+ # events = capture_notifications("sql.active_record") do
2935
+ # assert_equal expected_ids.size, scope.async_count.value
2936
+ # assert_equal expected_ids.sum, scope.async_sum(:id).value
2937
+ # assert_equal expected_ids.min, scope.async_minimum(:id).value
2938
+ # assert_equal expected_ids.max, scope.async_maximum(:id).value
2939
+ #
2940
+ # # Difference between original and coerced test is the use of `div` instead of `fdiv`.
2941
+ # assert_in_delta expected_ids.sum.div(expected_ids.size), scope.async_average(:id).value
2942
+ #
2943
+ # assert_equal expected_ids.min, scope.order(:id).async_pick(:id).value
2944
+ # assert_equal expected_ids, scope.order(:id).async_pluck(:id).value
2945
+ # assert_equal expected_ids, scope.order(:id).async_ids.value
2946
+ # assert_equal({1 => expected_ids.size}, scope.group(:author_id).async_count.value)
2947
+ # assert_equal expected_ids.size, Post.async_count_by_sql("SELECT COUNT(*) FROM posts WHERE title = 'In Transaction'").value
2948
+ # assert_equal expected_ids, Post.async_find_by_sql("SELECT * FROM posts WHERE title = 'In Transaction' ORDER BY id").value.map(&:id)
2949
+ # assert_equal expected_ids.size + 1, scope.async_count.then { |count| count + 1 }.value
2950
+ # end
2951
+ #
2952
+ # raise ActiveRecord::Rollback
2953
+ # end
2954
+ #
2955
+ # assert_not_empty events
2956
+ # assert events.none? { |event| event.payload[:async] }
2957
+ # end
2958
+ # end
@@ -13,6 +13,8 @@ class UtilsTestSQLServer < ActiveRecord::TestCase
13
13
 
14
14
  it ".quoted_raw" do
15
15
  _(SQLServer::Utils.quoted_raw("some.Name")).must_equal "[some.Name]"
16
+ _(SQLServer::Utils.quoted_raw("[a].[b]")).must_equal "[a].[b]"
17
+ _(SQLServer::Utils.quoted_raw("[a]; DROP TABLE x; --]")).must_equal "[[a]]; DROP TABLE x; --]]]"
16
18
  end
17
19
 
18
20
  describe ".extract_identifiers constructor and thus SQLServer::Utils::Name value object" do
@@ -92,6 +94,12 @@ class UtilsTestSQLServer < ActiveRecord::TestCase
92
94
  _(extract_identifiers("[obj.name].[foo]").quoted).must_equal "[obj.name].[foo]"
93
95
  end
94
96
 
97
+ it "escapes closing brackets inside identifiers that look already quoted" do
98
+ name = "[[id]; INSERT INTO table (id, value) VALUES (1, 'test'); -- ]]"
99
+ _(extract_identifiers(name).quoted).must_equal "[[id]]; INSERT INTO table (id, value) VALUES (1, 'test'); -- ]]]"
100
+ _(extract_identifiers("[a].[b]").quoted).must_equal "[a].[b]"
101
+ end
102
+
95
103
  it "should indicate if a name is fully qualified" do
96
104
  _(extract_identifiers("object").fully_qualified?).must_equal false
97
105
  _(extract_identifiers("schema.object").fully_qualified?).must_equal false
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: 8.1.4
4
+ version: 8.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
@@ -61,6 +61,7 @@ files:
61
61
  - ".github/workflows/ci.yml"
62
62
  - ".gitignore"
63
63
  - ".rubocop.yml"
64
+ - ".standard_todo.yml"
64
65
  - CHANGELOG.md
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Dockerfile.ci
@@ -245,8 +246,8 @@ licenses:
245
246
  - MIT
246
247
  metadata:
247
248
  bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
248
- changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v8.1.4/CHANGELOG.md
249
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v8.1.4
249
+ changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v8.1.5/CHANGELOG.md
250
+ source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v8.1.5
250
251
  rdoc_options: []
251
252
  require_paths:
252
253
  - lib