activerecord-sqlserver-adapter 5.2.0.rc1 → 5.2.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +7 -0
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +14 -18
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +1 -8
- data/test/cases/change_column_null_test_sqlserver.rb +42 -0
- data/test/cases/showplan_test_sqlserver.rb +12 -0
- data/test/migrations/create_clients_and_change_column_null.rb +23 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 86082ad4b36f21839ed6bde7e9400d53497d03f9fa20e7d05e88e5f44b908044
|
4
|
+
data.tar.gz: 5ff7193466b8db1c2bd86983be80b8ca0e95a5b59359c9d8baccb20a633950cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 353e197ded79e31d9f631c7b53a74e80c423de40da152dd0f65bfbf9a19b7427dd9c5e9106db42054e161a82a618a2c17034aa0a3990a333fdfec0fc7e4a8bdd
|
7
|
+
data.tar.gz: 1f4baeebc22334781cf45314bf98f22922edde9b5017f4c6bd1231dd06741f9769dc0497a7906eed696bf29dda1561789f1222b28d747302c3e39ecc8096a12b
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.2.0.
|
1
|
+
5.2.0.rc2
|
@@ -5,12 +5,11 @@ module ActiveRecord
|
|
5
5
|
module Explain
|
6
6
|
|
7
7
|
SQLSERVER_STATEMENT_PREFIX = 'EXEC sp_executesql '.freeze
|
8
|
-
|
9
|
-
SQLSERVER_NATIONAL_STRING_MATCHER = /N'(.*)'/m
|
8
|
+
SQLSERVER_STATEMENT_REGEXP = /N'(.+)', N'(.+)', (.+)/
|
10
9
|
|
11
10
|
def exec_explain(queries)
|
12
11
|
unprepared_queries = queries.map do |(sql, binds)|
|
13
|
-
[unprepare_sqlserver_statement(sql), binds]
|
12
|
+
[unprepare_sqlserver_statement(sql, binds), binds]
|
14
13
|
end
|
15
14
|
super(unprepared_queries)
|
16
15
|
end
|
@@ -19,22 +18,19 @@ module ActiveRecord
|
|
19
18
|
|
20
19
|
# This is somewhat hacky, but it should reliably reformat our prepared sql statment
|
21
20
|
# which uses sp_executesql to just the first argument, then unquote it. Likewise our
|
22
|
-
# `sp_executesql` method should substitude the @n args
|
23
|
-
def unprepare_sqlserver_statement(sql)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
unprepared_sql.sub! "@#{index}", value
|
33
|
-
end
|
34
|
-
unprepared_sql
|
35
|
-
else
|
36
|
-
sql
|
21
|
+
# `sp_executesql` method should substitude the @n args with the quoted values.
|
22
|
+
def unprepare_sqlserver_statement(sql, binds)
|
23
|
+
return sql unless sql.starts_with?(SQLSERVER_STATEMENT_PREFIX)
|
24
|
+
|
25
|
+
executesql = sql.from(SQLSERVER_STATEMENT_PREFIX.length)
|
26
|
+
executesql = executesql.match(SQLSERVER_STATEMENT_REGEXP).to_a[1]
|
27
|
+
|
28
|
+
binds.each_with_index do |bind, index|
|
29
|
+
value = connection.quote(bind)
|
30
|
+
executesql = executesql.sub("@#{index}", value)
|
37
31
|
end
|
32
|
+
|
33
|
+
executesql
|
38
34
|
end
|
39
35
|
|
40
36
|
end
|
@@ -258,7 +258,7 @@ module ActiveRecord
|
|
258
258
|
def change_column_null(table_name, column_name, allow_null, default = nil)
|
259
259
|
table_id = SQLServer::Utils.extract_identifiers(table_name)
|
260
260
|
column_id = SQLServer::Utils.extract_identifiers(column_name)
|
261
|
-
column =
|
261
|
+
column = column_for(table_name, column_name)
|
262
262
|
if !allow_null.nil? && allow_null == false && !default.nil?
|
263
263
|
do_execute("UPDATE #{table_id} SET #{column_id}=#{quote(default)} WHERE #{column_id} IS NULL")
|
264
264
|
end
|
@@ -492,13 +492,6 @@ module ActiveRecord
|
|
492
492
|
"DF_#{table_name}_#{column_name}"
|
493
493
|
end
|
494
494
|
|
495
|
-
def detect_column_for!(table_name, column_name)
|
496
|
-
unless column = schema_cache.columns(table_name).find { |c| c.name == column_name.to_s }
|
497
|
-
raise ActiveRecordError, "No such column: #{table_name}.#{column_name}"
|
498
|
-
end
|
499
|
-
column
|
500
|
-
end
|
501
|
-
|
502
495
|
def lowercase_schema_reflection_sql(node)
|
503
496
|
lowercase_schema_reflection ? "LOWER(#{node})" : node
|
504
497
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'cases/helper_sqlserver'
|
2
|
+
require 'migrations/create_clients_and_change_column_null'
|
3
|
+
|
4
|
+
class ChangeColumnNullTestSqlServer < ActiveRecord::TestCase
|
5
|
+
before do
|
6
|
+
@old_verbose = ActiveRecord::Migration.verbose
|
7
|
+
ActiveRecord::Migration.verbose = false
|
8
|
+
CreateClientsAndChangeColumnNull.new.up
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
CreateClientsAndChangeColumnNull.new.down
|
13
|
+
ActiveRecord::Migration.verbose = @old_verbose
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_column(table, name)
|
17
|
+
table.find { |column| column.name == name }
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:clients_table) { connection.columns('clients') }
|
21
|
+
let(:name_column) { find_column(clients_table, 'name') }
|
22
|
+
let(:code_column) { find_column(clients_table, 'code') }
|
23
|
+
let(:value_column) { find_column(clients_table, 'value') }
|
24
|
+
|
25
|
+
describe '#change_column_null' do
|
26
|
+
it 'does not change the column limit' do
|
27
|
+
name_column.limit.must_equal 15
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'does not change the column default' do
|
31
|
+
code_column.default.must_equal 'n/a'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not change the column precision' do
|
35
|
+
value_column.precision.must_equal 32
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not change the column scale' do
|
39
|
+
value_column.scale.must_equal 8
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -26,6 +26,18 @@ class ShowplanTestSQLServer < ActiveRecord::TestCase
|
|
26
26
|
plan.must_include "Clustered Index Scan", 'make sure we do not showplan the sp_executesql'
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'from array condition using index' do
|
30
|
+
plan = Car.where(id: [1, 2]).explain
|
31
|
+
plan.must_include " SELECT [cars].* FROM [cars] WHERE [cars].[id] IN (1, 2)"
|
32
|
+
plan.must_include "Clustered Index Seek", 'make sure we do not showplan the sp_executesql'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'from array condition' do
|
36
|
+
plan = Car.where(name: ['honda', 'zyke']).explain
|
37
|
+
plan.must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name] IN (N'honda', N'zyke')"
|
38
|
+
plan.must_include "Clustered Index Scan", 'make sure we do not showplan the sp_executesql'
|
39
|
+
end
|
40
|
+
|
29
41
|
end
|
30
42
|
|
31
43
|
describe 'With SHOWPLAN_TEXT option' do
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreateClientsAndChangeColumnNull < ActiveRecord::Migration[5.2]
|
2
|
+
def up
|
3
|
+
create_table :clients do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :code
|
6
|
+
t.decimal :value
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
change_column :clients, :name, :string, limit: 15
|
12
|
+
change_column :clients, :code, :string, default: 'n/a'
|
13
|
+
change_column :clients, :value, :decimal, precision: 32, scale: 8
|
14
|
+
|
15
|
+
change_column_null :clients, :name, false
|
16
|
+
change_column_null :clients, :code, false
|
17
|
+
change_column_null :clients, :value, false
|
18
|
+
end
|
19
|
+
|
20
|
+
def down
|
21
|
+
drop_table :clients
|
22
|
+
end
|
23
|
+
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: 5.2.0.
|
4
|
+
version: 5.2.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2019-
|
17
|
+
date: 2019-03-10 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activerecord
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- test/bin/install-openssl.sh
|
139
139
|
- test/bin/setup.sh
|
140
140
|
- test/cases/adapter_test_sqlserver.rb
|
141
|
+
- test/cases/change_column_null_test_sqlserver.rb
|
141
142
|
- test/cases/coerced_tests.rb
|
142
143
|
- test/cases/column_test_sqlserver.rb
|
143
144
|
- test/cases/connection_test_sqlserver.rb
|
@@ -163,6 +164,7 @@ files:
|
|
163
164
|
- test/config.yml
|
164
165
|
- test/debug.rb
|
165
166
|
- test/fixtures/1px.gif
|
167
|
+
- test/migrations/create_clients_and_change_column_null.rb
|
166
168
|
- test/migrations/transaction_table/1_table_will_never_be_created.rb
|
167
169
|
- test/models/sqlserver/booking.rb
|
168
170
|
- test/models/sqlserver/customers_view.rb
|
@@ -220,8 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
222
|
- !ruby/object:Gem::Version
|
221
223
|
version: 1.3.1
|
222
224
|
requirements: []
|
223
|
-
|
224
|
-
rubygems_version: 2.5.2.3
|
225
|
+
rubygems_version: 3.0.1
|
225
226
|
signing_key:
|
226
227
|
specification_version: 4
|
227
228
|
summary: ActiveRecord SQL Server Adapter.
|
@@ -232,6 +233,7 @@ test_files:
|
|
232
233
|
- test/bin/install-openssl.sh
|
233
234
|
- test/bin/setup.sh
|
234
235
|
- test/cases/adapter_test_sqlserver.rb
|
236
|
+
- test/cases/change_column_null_test_sqlserver.rb
|
235
237
|
- test/cases/coerced_tests.rb
|
236
238
|
- test/cases/column_test_sqlserver.rb
|
237
239
|
- test/cases/connection_test_sqlserver.rb
|
@@ -257,6 +259,7 @@ test_files:
|
|
257
259
|
- test/config.yml
|
258
260
|
- test/debug.rb
|
259
261
|
- test/fixtures/1px.gif
|
262
|
+
- test/migrations/create_clients_and_change_column_null.rb
|
260
263
|
- test/migrations/transaction_table/1_table_will_never_be_created.rb
|
261
264
|
- test/models/sqlserver/booking.rb
|
262
265
|
- test/models/sqlserver/customers_view.rb
|