activerecord-sqlserver-adapter 7.2.2 → 7.2.4

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: dba9ea79e6287b945d1c8fba8894559510999b58272b968f69953630d94eb484
4
- data.tar.gz: 9abcab548b00c1c906e26ebbb5f1d18982529c605452d447fba3b0a081f5046d
3
+ metadata.gz: e85a529bb9b684087f56962cc806b12aa3138de66dd85ad5985d364a4d749243
4
+ data.tar.gz: 5c5b790e60fc34d9c7ac5eb733f0cbd2b9b5e1dc0a821a5e8af02d1903204a7f
5
5
  SHA512:
6
- metadata.gz: cba19ac223013b55bc0d67fade1dc8b8d0a80dc05175bebcc5ba209e28a3980d271f8d9240a92ec8d2cebba2ae33049581d21c0a30c5f9e188ca9150909d5bb3
7
- data.tar.gz: e4feae1a11d2f000c1f75b81e6e5600a5abb0c08ea3220b26bf8d681aa881e34ebafb212ad0ae8a85280ae3d72401f27855e2af0e79f42521e6cdb5b56334907
6
+ metadata.gz: 1573a27c3712d8ab232b85d33710626988100e98f52f00f6d4d11ef0168c1c27f53ce1ab97b73708507d5ee2b53ee7093b56ab43ae2b75a73fa05554b4e482cf
7
+ data.tar.gz: ca4b98cad31184e0695249cfbf919f02b7c36798a60911d23bf389f3752f11adb055c52f68b8d61ae4116fa574f14b403312f9d39c4f59720c86fa9048802fbe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v7.2.4
2
+
3
+ #### Fixed
4
+
5
+ - [#1270](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1270) Fix parsing of raw table name from SQL with extra parentheses
6
+
7
+ ## v7.2.3
8
+
9
+ #### Fixed
10
+
11
+ - [#1262](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1262) Fix distinct alias when multiple databases used.
12
+
1
13
  ## v7.2.2
2
14
 
3
15
  #### Fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.2
1
+ 7.2.4
@@ -347,12 +347,16 @@ module ActiveRecord
347
347
 
348
348
  def columns_for_distinct(columns, orders)
349
349
  order_columns = orders.reject(&:blank?).map { |s|
350
- s = s.to_sql unless s.is_a?(String)
350
+ s = visitor.compile(s) unless s.is_a?(String)
351
351
  s.gsub(/\s+(?:ASC|DESC)\b/i, "")
352
352
  .gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, "")
353
- }.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
353
+ }
354
+ .reject(&:blank?)
355
+ .reject { |s| columns.include?(s) }
354
356
 
355
- (order_columns << super).join(", ")
357
+ order_columns_aliased = order_columns.map.with_index { |column, i| "#{column} AS alias_#{i}" }
358
+
359
+ (order_columns_aliased << super).join(", ")
356
360
  end
357
361
 
358
362
  def update_table_definition(table_name, base)
@@ -686,7 +690,7 @@ module ActiveRecord
686
690
  elsif s.match?(/^\s*UPDATE\s+.*/i)
687
691
  s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
688
692
  else
689
- s.match(/FROM\s+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
693
+ s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
690
694
  end.strip
691
695
  end
692
696
 
@@ -594,4 +594,13 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
594
594
  assert_equal Task.where("starting < ?", DateTime.current).count, 1
595
595
  end
596
596
  end
597
+
598
+ describe "distinct select query" do
599
+ it "generated SQL does not contain unnecessary alias projection" do
600
+ sqls = capture_sql do
601
+ Post.includes(:comments).joins(:comments).first
602
+ end
603
+ assert_no_match(/AS alias_0/, sqls.first)
604
+ end
605
+ end
597
606
  end
@@ -376,6 +376,18 @@ module ActiveRecord
376
376
  end
377
377
 
378
378
  class CalculationsTest < ActiveRecord::TestCase
379
+ # SELECT columns must be in the GROUP clause.
380
+ coerce_tests! :test_should_count_with_group_by_qualified_name_on_loaded
381
+ def test_should_count_with_group_by_qualified_name_on_loaded_coerced
382
+ accounts = Account.group("accounts.id").select("accounts.id")
383
+ expected = { 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1 }
384
+ assert_not_predicate accounts, :loaded?
385
+ assert_equal expected, accounts.count
386
+ accounts.load
387
+ assert_predicate accounts, :loaded?
388
+ assert_equal expected, accounts.count(:id)
389
+ end
390
+
379
391
  # Fix randomly failing test. The loading of the model's schema was affecting the test.
380
392
  coerce_tests! :test_offset_is_kept
381
393
  def test_offset_is_kept_coerced
@@ -101,5 +101,11 @@ class SchemaTestSQLServer < ActiveRecord::TestCase
101
101
  assert_equal "[with].[select notation]", connection.send(:get_raw_table_name, "INSERT INTO [with].[select notation] SELECT * FROM [table_name]")
102
102
  end
103
103
  end
104
+
105
+ describe 'CREATE VIEW statements' do
106
+ it do
107
+ assert_equal "test_table_as", connection.send(:get_raw_table_name, "CREATE VIEW test_views ( test_table_a_id, test_table_b_id ) AS SELECT test_table_as.id as test_table_a_id, test_table_bs.id as test_table_b_id FROM (test_table_as with(nolock) LEFT JOIN test_table_bs with(nolock) ON (test_table_as.id = test_table_bs.test_table_a_id))")
108
+ end
109
+ end
104
110
  end
105
111
  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.2.2
4
+ version: 7.2.4
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-11-10 00:00:00.000000000 Z
18
+ date: 2025-01-08 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -239,8 +239,8 @@ licenses:
239
239
  - MIT
240
240
  metadata:
241
241
  bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
242
- changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.2.2/CHANGELOG.md
243
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.2.2
242
+ changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.2.4/CHANGELOG.md
243
+ source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.2.4
244
244
  post_install_message:
245
245
  rdoc_options: []
246
246
  require_paths: