Skip to content

Commit f9c4e45

Browse files
authored
Merge branch '5-2-stable' into 5-1-stable-with-odbc
2 parents d3eb0f2 + c2916d7 commit f9c4e45

39 files changed

+658
-246
lines changed

.gitignore

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

.travis.yml

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ services:
44
- docker
55
env:
66
global:
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
7+
- COMPOSE_FILE: docker-compose.ci.yml
148
before_install:
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
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
2212
install:
23-
- export PATH=/opt/local/bin:$PATH
24-
- gem install bundler
25-
- bundle --version
26-
- bundle install
13+
- docker-compose build --build-arg TARGET_VERSION=$TARGET_VERSION
2714
script:
28-
- bundle exec rake
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

BACKERS.md

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

CHANGELOG.md

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

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

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

107
#### Fixed
118

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

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

1714
#### Fixed
1815

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
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.
4619

4720
#### Changed
4821

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

53-
* Support MismatchedForeignKey exception.
5424

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG TARGET_VERSION=2.6.3
2+
3+
FROM wpolicarpo/activerecord-sqlserver-adapter:${TARGET_VERSION}
4+
5+
ENV WORKDIR /activerecord-sqlserver-adapter
6+
7+
RUN mkdir -p $WORKDIR
8+
WORKDIR $WORKDIR
9+
10+
COPY . $WORKDIR
11+
12+
RUN bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
13+
14+
CMD ["sh"]

Gemfile

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

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

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
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-
1510
## About The Adapter
1611

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

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.
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.
2015

2116
#### Native Data Type Support
2217

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.
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.
2419

2520
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.
2621

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

137132
## Contributing
138133

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.
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.
140135

141136
* Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
142137
* 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.1.6
1+
5.2.0

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.1.0'
19+
spec.add_dependency 'activerecord', '~> 5.2.0'
2020
spec.add_dependency 'ruby-odbc'
2121
end

circle.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ dependencies:
1818
- openssl version
1919
- sudo ./test/bin/install-freetds.sh
2020
- tsql -C
21-
- rvm-exec 2.2.5 bundle install
22-
- rvm-exec 2.3.1 bundle install
23-
- rvm-exec 2.4.0 bundle install
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
2425

2526
database:
2627
override:
@@ -31,6 +32,7 @@ database:
3132

3233
test:
3334
override:
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
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

docker-compose.ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "2.2"
2+
services:
3+
database:
4+
image: metaskills/mssql-server-linux-rails
5+
ci:
6+
environment:
7+
- ACTIVERECORD_UNITTEST_HOST=database
8+
build: .
9+
command: wait-for database:1433 -- bundle exec rake test
10+
depends_on:
11+
- "database"

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

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

1111
def build_count_subquery(relation, column_name, distinct)
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)
12+
super(relation.unscope(:order), column_name, distinct)
13+
end
2314

24-
Arel::SelectManager.new(subquery).project(select_value)
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
2522
end
2623
end
2724
end
@@ -30,10 +27,6 @@ def build_count_subquery(relation, column_name, distinct)
3027
end
3128

3229
ActiveSupport.on_load(:active_record) do
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
30+
mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Calculations
31+
ActiveRecord::Relation.prepend(mod)
3932
end

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

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

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

1110
def exec_explain(queries)
1211
unprepared_queries = queries.map do |(sql, binds)|
13-
[unprepare_sqlserver_statement(sql), binds]
12+
[unprepare_sqlserver_statement(sql, binds), binds]
1413
end
1514
super(unprepared_queries)
1615
end
@@ -19,22 +18,19 @@ def exec_explain(queries)
1918

2019
# This is somewhat hacky, but it should reliably reformat our prepared sql statment
2120
# which uses sp_executesql to just the first argument, then unquote it. Likewise our
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
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)
3731
end
32+
33+
executesql
3834
end
3935

4036
end

lib/active_record/connection_adapters/sqlserver/database_limits.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module ActiveRecord
22
module ConnectionAdapters
33
module SQLServer
44
module DatabaseLimits
5-
65
def table_alias_length
76
128
87
end
@@ -32,7 +31,7 @@ def columns_per_multicolumn_index
3231
end
3332

3433
def in_clause_length
35-
65_536
34+
10_000
3635
end
3736

3837
def sql_query_length
@@ -43,6 +42,18 @@ def joins_per_query
4342
256
4443
end
4544

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
4657
end
4758
end
4859
end

0 commit comments

Comments
 (0)