Skip to content

Commit 2574b98

Browse files
committed
Revert "Merge branch '5-2-stable' into 5-1-stable-with-odbc"
This reverts commit f9c4e45, reversing changes made to d3eb0f2.
1 parent f9c4e45 commit 2574b98

39 files changed

+246
-658
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ Gemfile.lock
99
test/profile/output/*
1010
.rvmrc
1111
.rbenv-version
12-
.tool-versions
1312
.idea
1413
coverage/*
1514
.flooignore
16-
.floo
17-
.byebug_history
15+
.floo

.travis.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ services:
44
- docker
55
env:
66
global:
7-
- COMPOSE_FILE: docker-compose.ci.yml
7+
- TINYTDS_VERSION=2.1.0
8+
- ACTIVERECORD_UNITTEST_HOST=localhost
9+
- ACTIVERECORD_UNITTEST_DATASERVER=localhost
10+
rvm:
11+
- 2.2.5
12+
- 2.3.1
13+
- 2.4.0
814
before_install:
9-
- sudo rm /usr/local/bin/docker-compose
10-
- sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
11-
- sudo chmod +x /usr/local/bin/docker-compose
15+
- export PATH=/opt/local/bin:$PATH
16+
- docker info
17+
- sudo ./test/bin/setup.sh
18+
- sudo ./test/bin/install-openssl.sh
19+
- openssl version
20+
- sudo ./test/bin/install-freetds.sh
21+
- tsql -C
1222
install:
13-
- docker-compose build --build-arg TARGET_VERSION=$TARGET_VERSION
23+
- export PATH=/opt/local/bin:$PATH
24+
- gem install bundler
25+
- bundle --version
26+
- bundle install
1427
script:
15-
- docker-compose run ci
16-
matrix:
17-
include:
18-
- name: 2.3.8
19-
env: TARGET_VERSION=2.3.8
20-
- name: 2.4.6
21-
env: TARGET_VERSION=2.4.6
22-
- name: 2.5.5
23-
env: TARGET_VERSION=2.5.5
24-
- name: 2.6.3
25-
env: TARGET_VERSION=2.6.3
28+
- bundle exec rake

BACKERS.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Backers
2+
3+
You can join in supporting TinyTDS and the Rails SQL Server Adapter development by [pledging on Patreon](https://www.patreon.com/metaskills)! Backers in the same pledge level appear in the order of pledge date.
4+
5+
### $2000
6+
7+
[It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611218)
8+
9+
10+
### $500
11+
12+
[It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611209)
13+
14+
15+
### $250
16+
17+
[It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611199)
18+
19+
20+
### $100
21+
22+
[It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611196)
23+
24+
25+
### $50+
26+
27+
[It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611186)
28+
29+
30+
### $10+
31+
32+
[It could be you!](https://www.patreon.com/bePatron?c=765225&rid=1611149)

CHANGELOG.md

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,54 @@
1-
## v5.2.0
1+
## v5.1.6
22

3-
- #686 sql_for_insert set table name in case when pk is not nil
3+
#### Added
44

5-
## v5.2.0.rc2
5+
* Use lock hint when joining table in query.
6+
7+
8+
## v5.1.5
69

710
#### Fixed
811

9-
- #681 change_column_null should not clear other column attributes. Fixes #582.
10-
- #684 Fix explain with array conditions. Fixes #673.
12+
* Memoize `@@version` queries. Fixes #632
13+
1114

12-
## v5.2.0.rc1
15+
## v5.1.4
1316

1417
#### Fixed
1518

16-
- #638 Don't disable referential integrity for the same table twice.
17-
- #646 Make String equality check work for Type::Data values. Fixes #645.
18-
- #671 Fix tinyint columns schema migration. Fixes #670.
19+
* Add case insensitive comparison for better performance with CI collations. Fixes #624
20+
21+
22+
## v5.1.3
23+
24+
#### Fixed
25+
26+
* Use bigint type in sqlserver_type when needed. Fixes #616
27+
28+
29+
## v5.1.2
30+
31+
#### Fixed
32+
33+
* The `fast_string_to_time` method when zone local. Fixes #609 #614 #620
34+
* Patched `Relation#build_count_subquery`. Fixes #613.
35+
* Inserts to tables with triggers using default `OUTPUT INSERTED` style. Fixes #595.
36+
37+
38+
## v5.1.1
39+
40+
#### Fixed
41+
42+
* Use `ActiveSupport.on_load` to hook into ActiveRecord Fixes #588 #598
43+
44+
45+
## v5.1.0
1946

2047
#### Changed
2148

22-
- #642 Added with (nolock) hint to information_schema.views.
49+
* The `drop_table` with force cascade option now mimics in via pure SQL for us.
50+
51+
#### Added
2352

53+
* Support MismatchedForeignKey exception.
2454

25-
Please check [5-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/5-1-stable/CHANGELOG.md) for previous changes.

Dockerfile

Lines changed: 0 additions & 14 deletions
This file was deleted.

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ require 'openssl'
22
source 'https://rubygems.org'
33
gemspec
44

5-
gem 'sqlite3', '~> 1.3.6'
5+
gem 'sqlite3', '< 1.4'
6+
gem 'minitest', '< 5.3.4'
67
gem 'bcrypt'
78
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
89

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
* [![Dependency Status](https://dependencyci.com/github/rails-sqlserver/activerecord-sqlserver-adapter/badge)](https://dependencyci.com/github/rails-sqlserver/activerecord-sqlserver-adapter) - Dependency Status
88
* [![Gitter chat](https://img.shields.io/badge/%E2%8A%AA%20GITTER%20-JOIN%20CHAT%20%E2%86%92-brightgreen.svg?style=flat)](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) - Community
99

10+
## Supporting TinyTDS/Adapter
11+
12+
Both TinyTDS and the Rails SQL Server Adapter are MIT-licensed open source projects. Its ongoing development is made possible thanks to the support by these awesome [backers](https://github.com/rails-sqlserver/tiny_tds/blob/master/BACKERS.md). If you'd like to join them, check out our [Patreon Campaign](https://www.patreon.com/metaskills).
13+
14+
1015
## About The Adapter
1116

12-
The SQL Server adapter for ActiveRecord v5.2 using SQL Server 2012 or higher.
17+
The SQL Server adapter for ActiveRecord v5.1 using SQL Server 2012 or higher.
1318

14-
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 5.1.x version of the adapter is only for the latest 5.1 version of Rails. If you need the adapter for SQL Server 2008 or 2005, you 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 version. We also have stable branches for each major/minor release of ActiveRecord.
19+
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 5.0.x version of the adapter is only for the latest 5.0 version of Rails. If you need the adapter for SQL Server 2008 or 2005, you 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 version. We also have stable branches for each major/minor release of ActiveRecord.
1520

1621
#### Native Data Type Support
1722

18-
We support every data type supported by FreeTDS. All simplified Rails types in migrations will coorespond to a matching SQL Server national (unicode) data type. Always check the `initialize_native_database_types` [(here)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb) for an updated list.
23+
We support every data type supported by FreeTDS. All simplified Rails types in migrations will coorespond to a matching SQL Server national (unicode) data type. Always check the `initialize_native_database_types` [(here)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb#L243) for an updated list.
1924

2025
The following types (date, datetime2, datetimeoffset, time) all require TDS version 7.3 with TinyTDS. We recommend using FreeTDS 1.0 or higher which default to using `TDSVER` to "7.3". The adapter also sets TinyTDS's `tds_version` to this as well if non is specified.
2126

@@ -131,7 +136,7 @@ gem 'activerecord-sqlserver-adapter'
131136

132137
## Contributing
133138

134-
If you would like to contribute a feature or bugfix, thanks! To make sure your fix/feature has a high chance of being added, please read the following guidelines. First, ask on the Gitter, or post a ticket on github issues. Second, make sure there are tests! We will not accept any patch that is not tested. Please read the [`RUNNING_UNIT_TESTS`](RUNNING_UNIT_TESTS.md) file for the details of how to run the unit tests.
139+
If you would like to contribute a feature or bugfix, thanks! To make sure your fix/feature has a high chance of being added, please read the following guidelines. First, ask on the Gitter, or post a ticket on github issues. Second, make sure there are tests! We will not accept any patch that is not tested. Please read the `RUNNING_UNIT_TESTS` file for the details of how to run the unit tests.
135140

136141
* Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
137142
* Gitter: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.2.0
1+
5.1.6

activerecord-sqlserver-adapter.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Gem::Specification.new do |spec|
1616
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
1717
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1818
spec.require_paths = ['lib']
19-
spec.add_dependency 'activerecord', '~> 5.2.0'
19+
spec.add_dependency 'activerecord', '~> 5.1.0'
2020
spec.add_dependency 'ruby-odbc'
2121
end

circle.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ dependencies:
1818
- openssl version
1919
- sudo ./test/bin/install-freetds.sh
2020
- tsql -C
21-
- rvm-exec 2.3.8 bundle install
22-
- rvm-exec 2.4.5 bundle install
23-
- rvm-exec 2.5.3 bundle install
24-
- rvm-exec 2.6.0 bundle install
21+
- rvm-exec 2.2.5 bundle install
22+
- rvm-exec 2.3.1 bundle install
23+
- rvm-exec 2.4.0 bundle install
2524

2625
database:
2726
override:
@@ -32,7 +31,6 @@ database:
3231

3332
test:
3433
override:
35-
- rvm-exec 2.3.8 bundle exec rake test
36-
- rvm-exec 2.4.5 bundle exec rake test
37-
- rvm-exec 2.5.3 bundle exec rake test
38-
- rvm-exec 2.6.0 bundle exec rake test
34+
- rvm-exec 2.2.5 bundle exec rake test
35+
- rvm-exec 2.3.1 bundle exec rake test
36+
- rvm-exec 2.4.0 bundle exec rake test

docker-compose.ci.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ module Calculations
99
private
1010

1111
def build_count_subquery(relation, column_name, distinct)
12-
super(relation.unscope(:order), column_name, distinct)
13-
end
12+
relation.select_values = [
13+
if column_name == :all
14+
distinct ? table[Arel.star] : Arel.sql(FinderMethods::ONE_AS_ONE)
15+
else
16+
column_alias = Arel.sql("count_column")
17+
aggregate_column(column_name).as(column_alias)
18+
end
19+
]
20+
21+
subquery = relation.arel.as(Arel.sql("subquery_for_count"))
22+
select_value = operation_over_aggregate_column(column_alias || Arel.star, "count", false)
1423

15-
def type_cast_calculated_value(value, type, operation = nil)
16-
case operation
17-
when "count" then value.to_i
18-
when "sum" then type.deserialize(value || 0)
19-
when "average" then value&.respond_to?(:to_d) ? value.to_d : value
20-
else type.deserialize(value)
21-
end
24+
Arel::SelectManager.new(subquery).project(select_value)
2225
end
2326
end
2427
end
@@ -27,6 +30,10 @@ def type_cast_calculated_value(value, type, operation = nil)
2730
end
2831

2932
ActiveSupport.on_load(:active_record) do
30-
mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Calculations
31-
ActiveRecord::Relation.prepend(mod)
33+
if ActiveRecord::VERSION::MAJOR == 5 &&
34+
ActiveRecord::VERSION::MINOR == 1 &&
35+
ActiveRecord::VERSION::TINY >= 4
36+
mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Calculations
37+
ActiveRecord::Relation.prepend(mod)
38+
end
3239
end

lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ module CoreExt
55
module Explain
66

77
SQLSERVER_STATEMENT_PREFIX = 'EXEC sp_executesql '.freeze
8-
SQLSERVER_STATEMENT_REGEXP = /N'(.+)', N'(.+)', (.+)/
8+
SQLSERVER_PARAM_MATCHER = /@\d+ = (.*)/
9+
SQLSERVER_NATIONAL_STRING_MATCHER = /N'(.*)'/m
910

1011
def exec_explain(queries)
1112
unprepared_queries = queries.map do |(sql, binds)|
12-
[unprepare_sqlserver_statement(sql, binds), binds]
13+
[unprepare_sqlserver_statement(sql), binds]
1314
end
1415
super(unprepared_queries)
1516
end
@@ -18,19 +19,22 @@ def exec_explain(queries)
1819

1920
# This is somewhat hacky, but it should reliably reformat our prepared sql statment
2021
# which uses sp_executesql to just the first argument, then unquote it. Likewise our
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)
22+
# `sp_executesql` method should substitude the @n args withe the quoted values.
23+
def unprepare_sqlserver_statement(sql)
24+
if sql.starts_with?(SQLSERVER_STATEMENT_PREFIX)
25+
executesql = sql.from(SQLSERVER_STATEMENT_PREFIX.length)
26+
args = executesql.split(', ')
27+
unprepared_sql = args.shift.strip.match(SQLSERVER_NATIONAL_STRING_MATCHER)[1]
28+
unprepared_sql = Utils.unquote_string(unprepared_sql)
29+
args = args.from(args.length / 2)
30+
args.each_with_index do |arg, index|
31+
value = arg.match(SQLSERVER_PARAM_MATCHER)[1]
32+
unprepared_sql.sub! "@#{index}", value
33+
end
34+
unprepared_sql
35+
else
36+
sql
3137
end
32-
33-
executesql
3438
end
3539

3640
end

lib/active_record/connection_adapters/sqlserver/database_limits.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module ActiveRecord
22
module ConnectionAdapters
33
module SQLServer
44
module DatabaseLimits
5+
56
def table_alias_length
67
128
78
end
@@ -31,7 +32,7 @@ def columns_per_multicolumn_index
3132
end
3233

3334
def in_clause_length
34-
10_000
35+
65_536
3536
end
3637

3738
def sql_query_length
@@ -42,18 +43,6 @@ def joins_per_query
4243
256
4344
end
4445

45-
private
46-
47-
# The max number of binds is 2100, but because sp_executesql takes
48-
# the first 2 params as the query string and the list of types,
49-
# we have only 2098 spaces left
50-
def bind_params_length
51-
2_098
52-
end
53-
54-
def insert_rows_length
55-
1_000
56-
end
5746
end
5847
end
5948
end

0 commit comments

Comments
 (0)