Skip to content

Commit 67d1e62

Browse files
authored
Rails 5 (#502)
[Rails5] Initial work for basic adapter tests passing.
1 parent 316e71c commit 67d1e62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+665
-1005
lines changed

‎CHANGELOG.md

+6-196
Original file line numberDiff line numberDiff line change
@@ -1,212 +1,22 @@
1-
## v4.2.15
21

3-
#### Fixed
4-
5-
* Removed errand puts statment from database tasks.
6-
* Fix quoting of non-national columns.
7-
8-
9-
## v4.2.14
10-
11-
#### Fixed
12-
13-
* Fix rescue constants for optional connection gems. Fixes #475.
14-
15-
16-
## v4.2.13
17-
18-
#### Fixed
19-
20-
* Add to_s method to SQLServer::Type::Char::Data. Thanks @marceloeloelo.
21-
22-
23-
## v4.2.12
24-
25-
#### Fixed
26-
27-
* Isolation levels not being reset on error. Fixes #469. Thanks @anthony
28-
29-
30-
## v4.2.11
31-
32-
#### Fixed
33-
34-
* Undefined method `database_prefix_remote_server?' Fixes #450. Thanks @jippeholwerda
35-
* Document two methods for avoiding N'' quoting on char/varchar columns.
36-
* First run failure of `change_column` while dropping constraint. Fixes #420. Thanks @GrumpyRainbow @rkr090
37-
* Rounding errors w/datetime2(0) types having no fractional seconds. Fixes #465. Thanks @alawton
38-
39-
#### Changed
40-
41-
* Supporting escape hatch for N'' quoting. Remove `#is_utf8` string check in `#_quote` method.
42-
This duplicated strings and forced encoding which was actually wasteful.
43-
44-
45-
## v4.2.10
46-
47-
#### Fixed
48-
49-
* Ensure small datetime/datetime2 fractionals are properly quoted. Fixes #457.
50-
51-
52-
## v4.2.9
53-
54-
#### Fixed
55-
56-
* Conform to new data_sources interfaces. See: https://git.io/va4Fp
57-
* The `primary_key` method falls back to Identity columns. Not the other way around. Fixes #454. Thanks @marceloeloelo
58-
* Ensure that `execute_procedure` returns proper time zones. Fixes #449
59-
60-
#### Changed
61-
62-
* Run tests with verbose false.
63-
64-
65-
## v4.2.8
66-
67-
#### Fixed
68-
69-
* Azure-Friendly Disable Referential Integrity. No more `sp_MSforeachtable` usage. Fixes #421
70-
* Azure-Friendly DB create/drop. Fixes #442
71-
- Create allows edition options like: MAXSIZE, EDITION, and SERVICE_OBJECTIVE.
72-
73-
74-
## v4.2.7
75-
76-
#### Added
77-
78-
* Support 2008 Datatypes Using TDSVER=7.3. Fixes #433
79-
80-
#### Changed
81-
82-
* Test now use latest v0.9.5 of TinyTDS. Includes tests for `defncopy` Windows binstub.
83-
* Make linked servers stronger. Fixes #427. Thanks @jippeholwerda
84-
* Use proper module for the `sqlserver_connection` method. Fixes #431. Thanks @jippeholwerda
85-
* All datetime casting using the `Time::DATE_FORMATS[:_sqlserver_*]` formats set after connection.
86-
87-
#### Removed
88-
89-
* The `SQLServer::Utils.with_sqlserver_db_date_formats` helper and `quoted_date` hacks.
90-
* The `Quoter` value type which allowed column => type special case quoting.
91-
92-
#### Fixed
93-
94-
* Every time datatype has perfect micro/nano second handling.
95-
* All supported datatypes dump defaults properly to schema.rb
96-
* Partial indexes using `:where` in schema dumper. Fixes #153
97-
98-
99-
## v4.2.6
100-
101-
#### Fixed
102-
103-
* Allow linked servers for table names. Fixes #426. Thanks @jippeholwerda
104-
105-
106-
## v4.2.5
107-
108-
#### Removed
109-
110-
* Remove Type::Castable hacks for core type objects to force trust the DB. Allows Rails 5 attributes.
111-
112-
#### Fixed
113-
114-
* Tests for decimal scale. See Rails commit. http://git.io/vGotB
115-
* Improve case comparision performace per column. Fixes #414
116-
* DB rollback when reversable add_column has several options. Fixes #359
117-
* Better column definitions for default objects. Fixes #412
118-
119-
120-
## v4.2.4
121-
122-
#### Fixed
123-
124-
* Compatible with Rails 4.2.1.
125-
* Fix schema limit reflection for char/varchar. Fixes #394.
126-
127-
128-
## v4.2.3
129-
130-
#### Fixed
131-
132-
* Fix SET defaults when using Azure.
133-
* Test insert 4-byte unicode chars.
134-
* Make rollback transaction transcount aware for implicit error rollbacks. Fixes #390
135-
136-
137-
## v4.2.2
138-
139-
#### Added
140-
141-
* DatabaseTasks support for all tasks! Uses FreeTDS `defncopy` for structure dump. Fixes #380.
142-
* Provide class config for `use_output_inserted` (default true) for insert SQL. Fixed #381.
143-
144-
145-
## v4.2.1
146-
147-
#### Fixed
148-
149-
* Guard against empty view definitions when `sb_helptext` fails silently. Fixes #337.
150-
* Proper table/column escaping in the `change_column_null` method. Fixes #355.
151-
* Use `send :include` for modules for 1.9 compatibility. Fixes #383.
152-
153-
154-
## v4.2.0
2+
## v5.0.0
1553

1564
#### Added
1575

158-
* New `ActiveRecord::Type` objects. See `active_record/connection_adapters/sqlserver/type` dir.
159-
* Aliased `ActiveRecord::Type::SQLServer` to `ActiveRecord::ConnectionAdapters::SQLServer::Type`
160-
* New `SQLServer::Utils::Name` object for decomposing and quoting SQL Server names/identifiers.
161-
* Support for most all SQL Server types in schema statements and dumping.
162-
* Support create table with query from relation or select statement.
163-
* Foreign Key Support Fixes #375.
6+
* ...
1647

1658
#### Changed
1669

167-
* The `create_database` now takes an options hash. Only key/value now is `collation`. Unknown keys just use raw values for SQL.
168-
* Complete rewrite of our Arel visitor. Focuing on 2012 and upward so we can make FETCH happen.
169-
* Testing enhancements.
170-
* Guard support, check our Guardfile.
171-
* Use `ARTest` namespace with `SQLServer` module for our helpers/objects.
172-
* Simple 2012 schmea addition and extensive column/type_cast object tests.
173-
* Follow Rails convention and remove varying character default limits.
174-
* The `cs_equality_operator` is now s class configuration property only.
175-
* The `with_identity_insert_enabled(table_name)` is now public.
176-
* Use ActiveRecord tranasaction interface vs our own `run_with_isolation_level`.
10+
* ...
17711

17812
#### Deprecated
17913

180-
* n/a
14+
* ...
18115

18216
#### Removed
18317

184-
* SQL Server versions < 2012 which do not support OFFSET and FETCH. http://bit.ly/1B5Bwsd
185-
* The `enable_default_unicode_types` option. Default to national types all the time.
186-
* Native type configs for older DB support. Includes the following with new default value:
187-
* native_string_database_type => `nvarchar`
188-
* native_text_database_type => `nvarchar(max)`
189-
* native_binary_database_type => `varbinary(max)`
190-
* Various version and inspection methods removed. These include:
191-
* database_version
192-
* database_year
193-
* product_level
194-
* product_version
195-
* edition
196-
* Removed tests for old issue #164. Handled by core types now.
197-
* The `activity_stats` method. Please put this in a gem if needed.
198-
* We no longer use regular expressions to fix identity inserts. Use ActiveRecord or public ID insert helper.
199-
* All auto reconnect and SQL retry logic. Got too complicated and stood in the way of AR's pool. Speed boost too.
200-
* The adapter will no longer try to remove duplicate order by clauses. Use relation `reorder`, `unscope`, etc.
201-
* We no longer use regular expressions to remove identity columns from updates. Now with `attributes_for_update` AR hook.
18+
* ODBC connection mode. Not been maintained since Rails 4.0.
20219

20320
#### Fixed
20421

205-
* Default lock is now "WITH(UPDLOCK)". Fixes #368
206-
* Better bind types & params for `sp_executesql`. Fixes #239.
207-
208-
#### Security
209-
210-
* The connection's `inspect` method no longer returns sensitive connection info. Very basic now.
211-
212-
22+
* ...

‎Gemfile

+15-16
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ else
1616
require 'net/http'
1717
require 'yaml'
1818
spec = eval(File.read('activerecord-sqlserver-adapter.gemspec'))
19-
version = spec.dependencies.detect{ |d|d.name == 'activerecord' }.requirement.requirements.first.last.version
20-
major, minor, tiny = version.split('.')
21-
uri = URI.parse "https://rubygems.org/api/v1/versions/activerecord.yaml"
22-
http = Net::HTTP.new(uri.host, uri.port)
23-
http.use_ssl = true
24-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
25-
YAML.load(http.request(Net::HTTP::Get.new(uri.request_uri)).body).select do |data|
26-
a, b, c = data['number'].split('.')
27-
!data['prerelease'] && major == a && (minor.nil? || minor == b)
28-
end.first['number']
19+
ver = spec.dependencies.detect{ |d|d.name == 'activerecord' }.requirement.requirements.first.last.version
20+
major, minor, tiny, pre = ver.split('.')
21+
if !pre
22+
uri = URI.parse "https://rubygems.org/api/v1/versions/activerecord.yaml"
23+
http = Net::HTTP.new(uri.host, uri.port)
24+
http.use_ssl = true
25+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
26+
YAML.load(http.request(Net::HTTP::Get.new(uri.request_uri)).body).select do |data|
27+
a, b, c = data['number'].split('.')
28+
!data['prerelease'] && major == a && (minor.nil? || minor == b)
29+
end.first['number']
30+
else
31+
ver
32+
end
2933
end
3034
gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
3135
end
@@ -44,15 +48,10 @@ group :tinytds do
4448
end
4549
end
4650

47-
group :odbc do
48-
gem 'ruby-odbc'
49-
end
50-
5151
group :development do
52+
gem 'byebug'
5253
gem 'mocha'
53-
gem 'minitest', '< 5.3.4' # PENDING: [Rails5.x] Remove test order constraint.
5454
gem 'minitest-spec-rails'
55-
gem 'pry'
5655
end
5756

5857
group :guard do

‎README.md

-4
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ gem 'tiny_tds'
166166
gem 'activerecord-sqlserver-adapter', '~> 4.2.0'
167167
```
168168

169-
If you want to use ruby ODBC, please use the latest least. If you have any troubles installing the lower level libraries for the adapter, please consult the wiki pages for various platform installation guides. Tons of good info can be found and we ask that you contribute too!
170-
171-
http://wiki.github.com/rails-sqlserver/activerecord-sqlserver-adapter/platform-installation
172-
173169

174170
## Contributing
175171

‎RUNNING_UNIT_TESTS.md

-17
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ $ bundle exec rake test TEST_FILES_AR="test/cases/finder_test.rb"
2828

2929
The default names for the test databases are `activerecord_unittest` and `activerecord_unittest2`. If you want to use another database name then be sure to update the connection file that matches your connection method in test/connections/native_sqlserver_#{connection_method}/connection.rb. Define a user named 'rails' in SQL Server with all privileges granted for the test databases. Use an empty password for said user.
3030

31-
The connection files make certain assumptions. For instance, the ODBC connection assumes you have a DSN setup that matches the name of the default database names. Remember too you have to set an environment variable for the DSN of the adapter, see the connection.rb file that matches your connection mode for details.
32-
3331
```sql
3432
CREATE DATABASE [activerecord_unittest];
3533
CREATE DATABASE [activerecord_unittest2];
@@ -93,18 +91,6 @@ $ bundle exec rake test
9391

9492
## Testing Options
9593

96-
The Gemfile contains groups for `:tinytds` and `:odbc`. By default it will install both gems which allows you to run the full test suite in either connection mode. If for some reason any one of these is problematic or of no concern, you could always opt out of bundling either gem with something like this.
97-
98-
```
99-
$ bundle install --without odbc
100-
```
101-
102-
You can run different connection modes using the following rake commands. Again, the DBLIB connection mode using TinyTDS is the default test task.
103-
104-
```
105-
$ bundle exec rake test:dblib
106-
$ bundle exec rake test:odbc
107-
```
10894

10995
By default, Bundler will download the Rails git repo and use the git tag that matches the dependency version in our gemspec. If you want to test another version of Rails, you can either temporarily change the :tag for Rails in the Gemfile. Likewise, you can clone the Rails repo your self to another directory and use the `RAILS_SOURCE` environment variable.
11096

@@ -116,6 +102,3 @@ By default, Bundler will download the Rails git repo and use the git tag that ma
116102
* Possibly change the SQL Server TCP/IP properties in "SQL Server Configuration Manager -> SQL Server Network Configuration -> Protocols for MSSQLSERVER", and ensure that TCP/IP is enabled and the appropriate entries on the "IP Addresses" tab are enabled.
117103

118104

119-
## Current Expected Failures
120-
121-
* Misc Date/Time erros when using ODBC mode.

‎Rakefile

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ task default: [:test]
88

99
namespace :test do
1010

11-
%w(dblib odbc).each do |mode|
11+
%w(dblib).each do |mode|
1212

1313
Rake::TestTask.new(mode) do |t|
1414
t.libs = ARTest::SQLServer.test_load_paths
@@ -23,17 +23,12 @@ namespace :test do
2323
ENV['ARCONN'] = 'dblib'
2424
end
2525

26-
task 'odbc:env' do
27-
ENV['ARCONN'] = 'odbc'
28-
end
29-
3026
end
3127

3228
task 'test:dblib' => 'test:dblib:env'
33-
task 'test:odbc' => 'test:odbc:env'
3429

3530
namespace :profile do
36-
['dblib', 'odbc'].each do |mode|
31+
['dblib'].each do |mode|
3732
namespace mode.to_sym do
3833
Dir.glob('test/profile/*_profile_case.rb').sort.each do |test_file|
3934
profile_case = File.basename(test_file).sub('_profile_case.rb', '')

‎TODO.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
## SHORT TERM
3+
4+
Misc remidners while in the heat of adapting the adpater.
5+
6+
* Try removing `sp_executesql_sql_type` all together. Do we have to add more types?
7+
* Did we get the schema cache right?
8+
9+
10+
11+
## LONG TERM
12+
13+
After we get some tests passing
14+
15+
* Is `primary_keys(table_name)` performant? Contribute to rails for abstract adapter.
16+
* Check `sql_for_insert` can do without the table regular expresion.
17+
* Do we need the `query_requires_identity_insert` check in `execute`?
18+
* Will we have to add more Data types to our dates and use them in `quoted_date` or `quoted_string` or `_type_cast`?
19+
20+
21+
#### Use #without_prepared_statement?
22+
23+
I think we always send everything thru `sp_executesql`. Consider re-evaulating if there are no `binds` that we get any benefit from this. By doing so we also give the users the ability to turn this off completly. Would be neat to see how our prepared statments actually perform again.
24+
25+
```ruby
26+
def without_prepared_statement?(binds)
27+
!prepared_statements || binds.empty?
28+
end
29+
```
30+
31+
Maybe just quick bail to `do_execute`. Maybe related:
32+
33+
* [Do not cache prepared statements that are unlikely to have cache hits](https://github.com/rails/rails/commit/cbcdecd2)
34+
35+
36+
37+
38+
#### Does Find By SQL Work?
39+
40+
With binds and prepareable?
41+
42+
```ruby
43+
# Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
44+
# Post.find_by_sql ["SELECT body FROM comments WHERE author = :user_id OR approved_by = :user_id", { :user_id => user_id }]
45+
#
46+
def find_by_sql(sql, binds = [], preparable: nil)
47+
result_set = connection.select_all(sanitize_sql(sql), "#{name} Load", binds, preparable: preparable)
48+
```

‎VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.2.15
1+
5.0.0

‎activerecord-sqlserver-adapter.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ 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', '~> 4.2.1'
19+
spec.add_dependency 'activerecord', '~> 5.0.0'
2020
end

0 commit comments

Comments
 (0)