activerecord-sqlserver-adapter 7.2.3 → 7.2.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: 05376f4fb4ac7599dc2f61c926eed10a587bb21f34c68dc47de9025d2a031d6d
4
- data.tar.gz: cadbc6f8881d3f8cc70bfa2892abb3a7de2f6805c932c960bc0212c8376fc904
3
+ metadata.gz: a0c48184b9fac12f23a4db11b01d1ed3d670fdd48f8c9705c690c830b622f11e
4
+ data.tar.gz: 9e88d43c701da66870643b33684c9a2b2d58db063e419789d0b7faf6c5cf2e15
5
5
  SHA512:
6
- metadata.gz: 4ed7c2b41c36c70c0efc188421238224c80093d83430756028d3108402302cb75fe03ca8d07990322fd4c4f58d9e0da51b1180cd310963c34ebd11a15bab65ab
7
- data.tar.gz: 5a4e6f2a659c0fb23e0feadd04d8489f3ac9679767a94f4cf4e4da46de52f0cd70da617cada139ded171efbef2e342833b3967b8bdf2feb4eb48062eb8323d85
6
+ metadata.gz: 40567edb70c619f8b9ae007c41b9b1c05157862df8bb275494b1158648c87cad3971bc1d4080431696c623d48c42356cf826349b3cce36a762d9e7d68a0d3102
7
+ data.tar.gz: 162c65ce3cb0755f464798e0e55c651e72528f9e060c4dfd1d30ff8386fb54cbbe2f99c404f712a95c1567ec4892cc9833badcc73f8b4ce7469fdef8bdd2b039
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v7.2.5
2
+
3
+ #### Fixed
4
+
5
+ - [#1308](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1308) Fix retrieval of temporary table's column information.
6
+
7
+ ## v7.2.4
8
+
9
+ #### Fixed
10
+
11
+ - [#1270](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1270) Fix parsing of raw table name from SQL with extra parentheses
12
+
1
13
  ## v7.2.3
2
14
 
3
15
  #### Fixed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.3
1
+ 7.2.5
@@ -571,12 +571,22 @@ module ActiveRecord
571
571
  end
572
572
 
573
573
  def column_definitions_sql(database, identifier)
574
- object_name = prepared_statements ? "@0" : quote(identifier.object)
575
- schema_name = if identifier.schema.blank?
576
- "schema_name()"
577
- else
578
- prepared_statements ? "@1" : quote(identifier.schema)
579
- end
574
+ schema_name = "schema_name()"
575
+
576
+ if prepared_statements
577
+ object_name = "@0"
578
+ schema_name = "@1" if identifier.schema.present?
579
+ else
580
+ object_name = quote(identifier.object)
581
+ schema_name = quote(identifier.schema) if identifier.schema.present?
582
+ end
583
+
584
+ object_id_arg = identifier.schema.present? ? "CONCAT(#{schema_name},'.',#{object_name})" : object_name
585
+
586
+ if identifier.temporary_table?
587
+ database = "TEMPDB"
588
+ object_id_arg = "CONCAT('#{database}','..',#{object_name})"
589
+ end
580
590
 
581
591
  %{
582
592
  SELECT
@@ -631,7 +641,7 @@ module ActiveRecord
631
641
  AND k.unique_index_id = ic.index_id
632
642
  AND c.column_id = ic.column_id
633
643
  WHERE
634
- o.name = #{object_name}
644
+ o.Object_ID = Object_ID(#{object_id_arg})
635
645
  AND s.name = #{schema_name}
636
646
  ORDER BY
637
647
  c.column_id
@@ -653,7 +663,7 @@ module ActiveRecord
653
663
  end
654
664
 
655
665
  def remove_default_constraint(table_name, column_name)
656
- # If their are foreign keys in this table, we could still get back a 2D array, so flatten just in case.
666
+ # If there are foreign keys in this table, we could still get back a 2D array, so flatten just in case.
657
667
  execute_procedure(:sp_helpconstraint, table_name, "nomsg").flatten.select do |row|
658
668
  row["constraint_type"] == "DEFAULT on column #{column_name}"
659
669
  end.each do |row|
@@ -690,7 +700,7 @@ module ActiveRecord
690
700
  elsif s.match?(/^\s*UPDATE\s+.*/i)
691
701
  s.match(/UPDATE\s+([^\(\s]+)\s*/i)[1]
692
702
  else
693
- s.match(/FROM\s+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
703
+ s.match(/FROM[\s|\(]+((\[[^\(\]]+\])|[^\(\s]+)\s*/i)[1]
694
704
  end.strip
695
705
  end
696
706
 
@@ -81,6 +81,10 @@ module ActiveRecord
81
81
  parts.hash
82
82
  end
83
83
 
84
+ def temporary_table?
85
+ object.start_with?("#")
86
+ end
87
+
84
88
  protected
85
89
 
86
90
  def parse_raw_name
@@ -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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cases/helper_sqlserver"
4
+
5
+ class TemporaryTableSQLServer < ActiveRecord::TestCase
6
+ def test_insert_into_temporary_table
7
+ ActiveRecord::Base.with_connection do |conn|
8
+ conn.exec_query("CREATE TABLE #temp_users (id INT IDENTITY(1,1), name NVARCHAR(100))")
9
+
10
+ result = conn.exec_query("SELECT * FROM #temp_users")
11
+ assert_equal 0, result.count
12
+
13
+ conn.exec_query("INSERT INTO #temp_users (name) VALUES ('John'), ('Doe')")
14
+
15
+ result = conn.exec_query("SELECT * FROM #temp_users")
16
+ assert_equal 2, result.count
17
+ end
18
+ end
19
+ 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.3
4
+ version: 7.2.5
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-12-08 00:00:00.000000000 Z
18
+ date: 2025-03-10 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -177,6 +177,7 @@ files:
177
177
  - test/cases/schema_test_sqlserver.rb
178
178
  - test/cases/showplan_test_sqlserver.rb
179
179
  - test/cases/specific_schema_test_sqlserver.rb
180
+ - test/cases/temporary_table_test_sqlserver.rb
180
181
  - test/cases/transaction_test_sqlserver.rb
181
182
  - test/cases/trigger_test_sqlserver.rb
182
183
  - test/cases/utils_test_sqlserver.rb
@@ -239,8 +240,8 @@ licenses:
239
240
  - MIT
240
241
  metadata:
241
242
  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.3/CHANGELOG.md
243
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.2.3
243
+ changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.2.5/CHANGELOG.md
244
+ source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.2.5
244
245
  post_install_message:
245
246
  rdoc_options: []
246
247
  require_paths:
@@ -295,6 +296,7 @@ test_files:
295
296
  - test/cases/schema_test_sqlserver.rb
296
297
  - test/cases/showplan_test_sqlserver.rb
297
298
  - test/cases/specific_schema_test_sqlserver.rb
299
+ - test/cases/temporary_table_test_sqlserver.rb
298
300
  - test/cases/transaction_test_sqlserver.rb
299
301
  - test/cases/trigger_test_sqlserver.rb
300
302
  - test/cases/utils_test_sqlserver.rb