activerecord-sqlserver-adapter 7.2.7 → 8.0.0

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: e4cecbb9e30775c962ac1ce665548b88081fc41501177c3e96abb3739d5d3c8a
4
- data.tar.gz: 46b36bbe894e2023475765deebcb2b0ff38af31c6341aff3c56920d5bed77e00
3
+ metadata.gz: 926f65915d98bb3c271370883fa89891fc575b5c6801cd8c235386c078d34bf5
4
+ data.tar.gz: 0a932a9d5edf0d3932e3f0ba44328ed77a033a1223f05699e8f4caa79116ac56
5
5
  SHA512:
6
- metadata.gz: f978e149eb3c53fe1bd199fcbe533aef919dbbb6b076530e8a8d6e5e7dab9735a3f4ce98d3e27057ec2de18ba28c6a810b465f1b1525de14f75261226ca35b78
7
- data.tar.gz: 8f30ad18a93884f2779d29850b19c2510c6a8c75455be38a25121912665355d799f2f1bb5d94664eb773b715ff45bb85e8244ec3afb4797f8dc5826b6c8f3f78
6
+ metadata.gz: ee45540a8d2ae57dc69a35048f4ccfbf01bcfc91e177e57405b19ccb8a3279eef7b752c22dee20c4171c8bb4e2cb0fcaadb99cd6c25d139fd2ef53577a5cb23a
7
+ data.tar.gz: 9184a7041e5de445103bcd47832352614897865f0ef49e83067b553786d089be73eb73c34dfaf3f102e02804ee7d8d40803d5582430ebfeecbe95f568b0b7cb7
@@ -1,12 +1,17 @@
1
1
  name: CI
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+ schedule:
9
+ - cron: '0 4 * * 1'
4
10
 
5
11
  jobs:
6
12
  test:
7
13
  name: Run test suite
8
- runs-on: ubuntu-latest
9
- timeout-minutes: 10
14
+ runs-on: ubuntu-20.04 # TODO: Change back to 'ubuntu-latest' when https://github.com/microsoft/mssql-docker/issues/899 resolved.
10
15
 
11
16
  env:
12
17
  COMPOSE_FILE: docker-compose.ci.yml
@@ -15,9 +20,8 @@ jobs:
15
20
  fail-fast: false
16
21
  matrix:
17
22
  ruby:
18
- - 3.1.6
19
- - 3.2.4
20
- - 3.3.2
23
+ - 3.3.4
24
+ - 3.2.5
21
25
 
22
26
  steps:
23
27
  - name: Checkout code
data/CHANGELOG.md CHANGED
@@ -1,62 +1,12 @@
1
- ## v7.2.7
1
+ ## v8.0.0
2
2
 
3
3
  #### Changed
4
4
 
5
- - [#1341](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1341) Support more Azure services by changing language source.
5
+ - [#1216](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1216) Refactor adapter interface to match abstract adapter
6
+ - [#1225](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1225) Drop support to Ruby 3.1
6
7
 
7
8
  #### Fixed
8
9
 
9
- - [#1357](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1357) Support cross database inserts.
10
+ - [#1215](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1215) Fix mismatched foreign key errors
10
11
 
11
- ## v7.2.6
12
-
13
- #### Fixed
14
-
15
- - [#1333](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1333) Enable identity insert on view's base table for fixtures.
16
-
17
- ## v7.2.5
18
-
19
- #### Fixed
20
-
21
- - [#1308](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1308) Fix retrieval of temporary table's column information.
22
-
23
- ## v7.2.4
24
-
25
- #### Fixed
26
-
27
- - [#1270](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1270) Fix parsing of raw table name from SQL with extra parentheses
28
-
29
- ## v7.2.3
30
-
31
- #### Fixed
32
-
33
- - [#1262](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1262) Fix distinct alias when multiple databases used.
34
-
35
- ## v7.2.2
36
-
37
- #### Fixed
38
-
39
- - [#1244](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1244) Allow INSERT statements with SELECT notation
40
- - [#1247](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1247) Fix queries with date and date-time placeholder conditions
41
- - [#1249](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1249) Binary basic columns should be limitable
42
- - [#1255](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1255) Fixed the ordering of optimizer hints in the generated SQL
43
-
44
- ## v7.2.1
45
-
46
- #### Fixed
47
-
48
- - [#1231](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1231) Enable identity insert on view's base table
49
-
50
- ## v7.2.0
51
-
52
- #### Added
53
-
54
- - [#1178](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1178) Support encrypting binary columns
55
-
56
- #### Changed
57
-
58
- - [#1153](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1153) Only support Ruby v3.1+
59
- - [#1196](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1196) Use default inspect for database adapter
60
-
61
-
62
- Please check [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/7-1-stable/CHANGELOG.md) for previous changes.
12
+ Please check [7-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/7-2-stable/CHANGELOG.md) for previous changes.
data/Dockerfile.ci CHANGED
@@ -9,6 +9,6 @@ WORKDIR $WORKDIR
9
9
 
10
10
  COPY . $WORKDIR
11
11
 
12
- RUN RAILS_BRANCH=7-2-stable bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
12
+ RUN bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
13
13
 
14
14
  CMD ["sh"]
data/Gemfile CHANGED
@@ -18,6 +18,8 @@ if ENV["RAILS_SOURCE"]
18
18
  gemspec path: ENV["RAILS_SOURCE"]
19
19
  elsif ENV["RAILS_BRANCH"]
20
20
  gem "rails", github: "rails/rails", branch: ENV["RAILS_BRANCH"]
21
+ elsif ENV["RAILS_COMMIT"]
22
+ gem "rails", github: "rails/rails", ref: ENV["RAILS_COMMIT"]
21
23
  else
22
24
  # Need to get rails source because the gem doesn't include tests
23
25
  version = ENV["RAILS_VERSION"] || begin
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
1
+ # ActiveRecord SQL Server Adapter
2
2
 
3
3
  * [![CI](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/workflows/ci.yml) - CI
4
4
  * [![Gem Version](http://img.shields.io/gem/v/activerecord-sqlserver-adapter.svg)](https://rubygems.org/gems/activerecord-sqlserver-adapter) - Gem Version
@@ -8,15 +8,18 @@
8
8
 
9
9
  The SQL Server adapter for ActiveRecord using SQL Server 2012 or higher.
10
10
 
11
- Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 7.x version
12
- 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
13
- 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
14
- version. We also have stable branches for each major/minor release of ActiveRecord. For older versions, please check
15
- their stable branches.
11
+ We follow a rational versioning policy that tracks Rails. That means that our 7.x version of the adapter is only
12
+ for the latest 7.x version of Rails. We also have stable branches for each major/minor release of ActiveRecord.
13
+
14
+ We support the versions of the adapter that are in the Rails [Bug Fixes](https://rubyonrails.org/maintenance)
15
+ maintenance group.
16
+
17
+ See [Rubygems](https://rubygems.org/gems/activerecord-sqlserver-adapter/versions) for the latest version of the adapter for each Rails release.
16
18
 
17
19
  | Adapter Version | Rails Version | Support | Branch |
18
20
  |-----------------|---------------|----------------|-------------------------------------------------------------------------------------------------|
19
- | `7.2.x` | `7.2.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
21
+ | `8.0.0` | `8.0.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
22
+ | `7.2.x` | `7.2.x` | Active | [7-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-2-stable) |
20
23
  | `7.1.x` | `7.1.x` | Active | [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-1-stable) |
21
24
  | `7.0.x` | `7.0.x` | Ended | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
22
25
  | `6.1.x` | `6.1.x` | Ended | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
@@ -26,7 +29,6 @@ their stable branches.
26
29
  | `4.2.x` | `4.2.x` | Ended | [4-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
27
30
  | `4.1.x` | `4.1.x` | Ended | [4-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
28
31
 
29
- See [Rubygems](https://rubygems.org/gems/activerecord-sqlserver-adapter/versions) for the latest version of the adapter for each Rails release.
30
32
 
31
33
  #### Native Data Type Support
32
34
 
@@ -103,16 +105,14 @@ configuration then implement the `configure_connection` method in an initializer
103
105
  example we are setting the `TEXTSIZE` to 64 megabytes.
104
106
 
105
107
  ```ruby
106
- module ActiveRecord
107
- module ConnectionAdapters
108
- class SQLServerAdapter < AbstractAdapter
109
- def configure_connection
110
- super
111
- @raw_connection.execute("SET TEXTSIZE #{64.megabytes}").do
112
- end
108
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.prepend(
109
+ Module.new do
110
+ def configure_connection
111
+ super
112
+ @raw_connection.execute("SET TEXTSIZE #{64.megabytes}").do
113
113
  end
114
114
  end
115
- end
115
+ )
116
116
  ```
117
117
 
118
118
  #### Configure Application Name
@@ -262,7 +262,6 @@ Many many people have contributed. If you do not see your name here and it shoul
262
262
 
263
263
  You can see an up-to-date list of contributors here: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/contributors
264
264
 
265
-
266
265
  ## License
267
266
 
268
267
  ActiveRecord SQL Server Adapter is released under the [MIT License](https://opensource.org/licenses/MIT).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.7
1
+ 8.0.0
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.version = version
9
9
 
10
- spec.required_ruby_version = ">= 3.1.0"
10
+ spec.required_ruby_version = ">= 3.2.0"
11
11
 
12
12
  spec.license = "MIT"
13
13
  spec.authors = ["Ken Collins", "Anna Carey", "Will Bond", "Murray Steele", "Shawn Balestracci", "Joe Rafaniello", "Tom Ward", "Aidan Haran"]
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "activerecord", "~> 7.2.0"
30
+ spec.add_dependency "activerecord", "~> 8.0.0"
31
31
  spec.add_dependency "tiny_tds"
32
32
  end
@@ -5,7 +5,6 @@ services:
5
5
  ci:
6
6
  environment:
7
7
  - ACTIVERECORD_UNITTEST_HOST=sqlserver
8
- - RAILS_BRANCH=7-2-stable
9
8
  build:
10
9
  context: .
11
10
  dockerfile: Dockerfile.ci
@@ -11,7 +11,7 @@ module ActiveRecord
11
11
  private
12
12
 
13
13
  def construct_relation_for_exists(conditions)
14
- klass.with_connection do |connection|
14
+ model.with_connection do |connection|
15
15
  if connection.sqlserver?
16
16
  _construct_relation_for_exists(conditions)
17
17
  else
@@ -13,47 +13,42 @@ module ActiveRecord
13
13
  !READ_QUERY.match?(sql.b)
14
14
  end
15
15
 
16
- def raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: true)
17
- log(sql, name, async: async) do |notification_payload|
18
- with_raw_connection(allow_retry: allow_retry, materialize_transactions: materialize_transactions) do |conn|
19
- result = if id_insert_table_name = query_requires_identity_insert?(sql)
20
- with_identity_insert_enabled(id_insert_table_name, conn) { internal_raw_execute(sql, conn, perform_do: true) }
21
- else
22
- internal_raw_execute(sql, conn, perform_do: true)
23
- end
24
- verified!
25
- notification_payload[:row_count] = result
26
- result
27
- end
16
+ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch:)
17
+ result = if id_insert_table_name = query_requires_identity_insert?(sql)
18
+ # If the table name is a view, we need to get the base table name for enabling identity insert.
19
+ id_insert_table_name = view_table_name(id_insert_table_name) if view_exists?(id_insert_table_name)
20
+
21
+ with_identity_insert_enabled(id_insert_table_name, raw_connection) do
22
+ internal_exec_sql_query(sql, raw_connection)
23
+ end
24
+ else
25
+ internal_exec_sql_query(sql, raw_connection)
26
+ end
27
+
28
+ verified!
29
+ notification_payload[:row_count] = result.count
30
+ result
31
+ end
32
+
33
+ def cast_result(raw_result)
34
+ if raw_result.columns.empty?
35
+ ActiveRecord::Result.empty
36
+ else
37
+ ActiveRecord::Result.new(raw_result.columns, raw_result.rows)
28
38
  end
29
39
  end
30
40
 
31
- def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false)
32
- sql = transform_query(sql)
33
-
34
- check_if_write_query(sql)
35
- mark_transaction_written_if_write(sql)
41
+ def affected_rows(raw_result)
42
+ raw_result.first['AffectedRows']
43
+ end
36
44
 
37
- unless without_prepared_statement?(binds)
45
+ def raw_execute(sql, name = nil, binds = [], prepare: false, async: false, allow_retry: false, materialize_transactions: true, batch: false)
46
+ unless binds.nil? || binds.empty?
38
47
  types, params = sp_executesql_types_and_parameters(binds)
39
48
  sql = sp_executesql_sql(sql, types, params, name)
40
49
  end
41
50
 
42
- log(sql, name, binds, async: async) do |notification_payload|
43
- with_raw_connection do |conn|
44
- result = if id_insert_table_name = query_requires_identity_insert?(sql)
45
- with_identity_insert_enabled(id_insert_table_name, conn) do
46
- internal_exec_sql_query(sql, conn)
47
- end
48
- else
49
- internal_exec_sql_query(sql, conn)
50
- end
51
-
52
- verified!
53
- notification_payload[:row_count] = result.count
54
- result
55
- end
56
- end
51
+ super
57
52
  end
58
53
 
59
54
  def internal_exec_sql_query(sql, conn)
@@ -63,14 +58,14 @@ module ActiveRecord
63
58
  finish_statement_handle(handle)
64
59
  end
65
60
 
66
- def exec_delete(sql, name, binds)
61
+ def exec_delete(sql, name = nil, binds = [])
67
62
  sql = sql.dup << "; SELECT @@ROWCOUNT AS AffectedRows"
68
- super(sql, name, binds).rows.first.first
63
+ super(sql, name, binds)
69
64
  end
70
65
 
71
- def exec_update(sql, name, binds)
66
+ def exec_update(sql, name = nil, binds = [])
72
67
  sql = sql.dup << "; SELECT @@ROWCOUNT AS AffectedRows"
73
- super(sql, name, binds).rows.first.first
68
+ super(sql, name, binds)
74
69
  end
75
70
 
76
71
  def begin_db_transaction
@@ -153,7 +148,7 @@ module ActiveRecord
153
148
  returning_sql = if returning.is_a?(String)
154
149
  returning
155
150
  else
156
- returning.map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
151
+ Array(returning).map { |column| "INSERTED.#{quote_column_name(column)}" }.join(", ")
157
152
  end
158
153
  sql << " OUTPUT #{returning_sql}"
159
154
  end
@@ -191,14 +186,11 @@ module ActiveRecord
191
186
  end
192
187
 
193
188
  def with_identity_insert_enabled(table_name, conn)
194
- # If the table name is a view, we need to get the base table name for enabling identity insert.
195
- table_name = view_table_name(table_name) if view_exists?(table_name)
196
- quoted_table_name = quote_table_name(table_name)
197
-
198
- set_identity_insert(quoted_table_name, conn, true)
189
+ table_name = quote_table_name(table_name)
190
+ set_identity_insert(table_name, conn, true)
199
191
  yield
200
192
  ensure
201
- set_identity_insert(quoted_table_name, conn, false)
193
+ set_identity_insert(table_name, conn, false)
202
194
  end
203
195
 
204
196
  def use_database(database = nil)
@@ -228,7 +220,7 @@ module ActiveRecord
228
220
 
229
221
  def user_options_dateformat
230
222
  if sqlserver_azure?
231
- select_value "SELECT [dateformat] FROM [sys].[syslanguages] WHERE [name] = @@LANGUAGE", "SCHEMA"
223
+ select_value "SELECT [dateformat] FROM [sys].[syslanguages] WHERE [langid] = @@LANGID", "SCHEMA"
232
224
  else
233
225
  user_options["dateformat"]
234
226
  end
@@ -332,10 +324,13 @@ module ActiveRecord
332
324
 
333
325
  def sp_executesql_sql_type(attr)
334
326
  if attr.respond_to?(:type)
335
- return attr.type.sqlserver_type if attr.type.respond_to?(:sqlserver_type)
327
+ type = attr.type.is_a?(ActiveRecord::Normalization::NormalizedValueType) ? attr.type.cast_type : attr.type
328
+ type = type.subtype if type.serialized?
329
+
330
+ return type.sqlserver_type if type.respond_to?(:sqlserver_type)
336
331
 
337
- if attr.type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType) && attr.type.instance_variable_get(:@cast_type).respond_to?(:sqlserver_type)
338
- return attr.type.instance_variable_get(:@cast_type).sqlserver_type
332
+ if type.is_a?(ActiveRecord::Encryption::EncryptedAttributeType) && type.instance_variable_get(:@cast_type).respond_to?(:sqlserver_type)
333
+ return type.instance_variable_get(:@cast_type).sqlserver_type
339
334
  end
340
335
  end
341
336
 
@@ -375,6 +370,7 @@ module ActiveRecord
375
370
  sql = "EXEC sp_executesql #{quote(sql)}"
376
371
  sql += ", #{types}, #{params}" unless params.empty?
377
372
  end
373
+
378
374
  sql.freeze
379
375
  end
380
376
 
@@ -452,10 +448,9 @@ module ActiveRecord
452
448
  # TinyTDS returns false instead of raising an exception if connection fails.
453
449
  # Getting around this by raising an exception ourselves while PR
454
450
  # https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
455
- def internal_raw_execute(sql, conn, perform_do: false)
456
- result = conn.execute(sql).tap do |_result|
457
- raise TinyTds::Error, "failed to execute statement" if _result.is_a?(FalseClass)
458
- end
451
+ def internal_raw_execute(sql, raw_connection, perform_do: false)
452
+ result = raw_connection.execute(sql)
453
+ raise TinyTds::Error, "failed to execute statement" if result.is_a?(FalseClass)
459
454
 
460
455
  perform_do ? result.do : result
461
456
  end