activerecord-sqlserver-adapter_new 4.2.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/CHANGELOG.md +212 -0
- data/CODE_OF_CONDUCT.md +31 -0
- data/Gemfile +61 -0
- data/Guardfile +29 -0
- data/MIT-LICENSE +20 -0
- data/README.md +201 -0
- data/RUNNING_UNIT_TESTS.md +121 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/activerecord-sqlserver-adapter_new.gemspec +20 -0
- data/appveyor.yml +39 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +27 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +25 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +40 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb +34 -0
- data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +49 -0
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +386 -0
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +68 -0
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +7 -0
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +69 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_cache.rb +114 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +52 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +473 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +66 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +66 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +22 -0
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +76 -0
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +57 -0
- data/lib/active_record/connection_adapters/sqlserver/type.rb +46 -0
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +38 -0
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +21 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +41 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +17 -0
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +31 -0
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +21 -0
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +13 -0
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +21 -0
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +22 -0
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +40 -0
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +76 -0
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +22 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +12 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +15 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +23 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +136 -0
- data/lib/active_record/connection_adapters/sqlserver/version.rb +11 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +405 -0
- data/lib/active_record/connection_adapters/sqlserver_column.rb +53 -0
- data/lib/active_record/sqlserver_base.rb +20 -0
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +131 -0
- data/lib/activerecord-sqlserver-adapter.rb +1 -0
- data/lib/arel/visitors/sqlserver.rb +214 -0
- data/lib/arel_sqlserver.rb +3 -0
- data/test/appveyor/dbsetup.ps1 +27 -0
- data/test/appveyor/dbsetup.sql +11 -0
- data/test/cases/adapter_test_sqlserver.rb +444 -0
- data/test/cases/coerced_tests.rb +713 -0
- data/test/cases/column_test_sqlserver.rb +780 -0
- data/test/cases/connection_test_sqlserver.rb +142 -0
- data/test/cases/execute_procedure_test_sqlserver.rb +44 -0
- data/test/cases/fetch_test_sqlserver.rb +57 -0
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +76 -0
- data/test/cases/helper_sqlserver.rb +54 -0
- data/test/cases/migration_test_sqlserver.rb +61 -0
- data/test/cases/order_test_sqlserver.rb +147 -0
- data/test/cases/pessimistic_locking_test_sqlserver.rb +90 -0
- data/test/cases/rake_test_sqlserver.rb +163 -0
- data/test/cases/schema_dumper_test_sqlserver.rb +198 -0
- data/test/cases/schema_test_sqlserver.rb +54 -0
- data/test/cases/scratchpad_test_sqlserver.rb +9 -0
- data/test/cases/showplan_test_sqlserver.rb +65 -0
- data/test/cases/specific_schema_test_sqlserver.rb +167 -0
- data/test/cases/transaction_test_sqlserver.rb +66 -0
- data/test/cases/utils_test_sqlserver.rb +129 -0
- data/test/cases/uuid_test_sqlserver.rb +48 -0
- data/test/config.yml +41 -0
- data/test/debug.rb +14 -0
- data/test/fixtures/1px.gif +0 -0
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +11 -0
- data/test/models/sqlserver/booking.rb +3 -0
- data/test/models/sqlserver/customers_view.rb +3 -0
- data/test/models/sqlserver/datatype.rb +3 -0
- data/test/models/sqlserver/datatype_migration.rb +3 -0
- data/test/models/sqlserver/dollar_table_name.rb +3 -0
- data/test/models/sqlserver/dot_table_name.rb +3 -0
- data/test/models/sqlserver/edge_schema.rb +13 -0
- data/test/models/sqlserver/fk_has_fk.rb +3 -0
- data/test/models/sqlserver/fk_has_pk.rb +3 -0
- data/test/models/sqlserver/natural_pk_data.rb +4 -0
- data/test/models/sqlserver/natural_pk_int_data.rb +3 -0
- data/test/models/sqlserver/no_pk_data.rb +3 -0
- data/test/models/sqlserver/object_default.rb +3 -0
- data/test/models/sqlserver/quoted_table.rb +7 -0
- data/test/models/sqlserver/quoted_view_1.rb +3 -0
- data/test/models/sqlserver/quoted_view_2.rb +3 -0
- data/test/models/sqlserver/string_default.rb +3 -0
- data/test/models/sqlserver/string_defaults_big_view.rb +3 -0
- data/test/models/sqlserver/string_defaults_view.rb +3 -0
- data/test/models/sqlserver/tinyint_pk.rb +3 -0
- data/test/models/sqlserver/upper.rb +3 -0
- data/test/models/sqlserver/uppered.rb +3 -0
- data/test/models/sqlserver/uuid.rb +3 -0
- data/test/schema/datatypes/2012.sql +55 -0
- data/test/schema/sqlserver_specific_schema.rb +207 -0
- data/test/support/coerceable_test_sqlserver.rb +45 -0
- data/test/support/connection_reflection.rb +37 -0
- data/test/support/load_schema_sqlserver.rb +29 -0
- data/test/support/minitest_sqlserver.rb +1 -0
- data/test/support/paths_sqlserver.rb +50 -0
- data/test/support/rake_helpers.rb +41 -0
- data/test/support/sql_counter_sqlserver.rb +32 -0
- metadata +253 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96c2b81904bd08d86b127ca1486cb19017fd2c97
|
4
|
+
data.tar.gz: 8c2762e054f44f8b5a950784a8b5b21d714fafff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22736f0d9a558d4c77ebeeaf5b5e653295615dae7cebd99f12aa12628ac6ff17a58521d1258ddeb2c1d47247f906f683b39965a6774eb20027cc608e667c40b3
|
7
|
+
data.tar.gz: 75505c98b5ce2269840bfd8fadb1254a5cd6a91fe5b25df6cb032a9e25673ae34becad8192bfd9747e820efee11164af4715093a34fc4a01212fb4b362035f06
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
## v4.2.15
|
2
|
+
|
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
|
155
|
+
|
156
|
+
#### Added
|
157
|
+
|
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.
|
164
|
+
|
165
|
+
#### Changed
|
166
|
+
|
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`.
|
177
|
+
|
178
|
+
#### Deprecated
|
179
|
+
|
180
|
+
* n/a
|
181
|
+
|
182
|
+
#### Removed
|
183
|
+
|
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.
|
202
|
+
|
203
|
+
#### Fixed
|
204
|
+
|
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
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all
|
4
|
+
people who contribute through reporting issues, posting feature requests,
|
5
|
+
updating documentation, submitting pull requests or patches, and other
|
6
|
+
activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, or religion.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include the use of sexual
|
14
|
+
language or imagery, derogatory comments or personal attacks, trolling, public
|
15
|
+
or private harassment, insults, or other unprofessional conduct.
|
16
|
+
|
17
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
18
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
19
|
+
that are not aligned to this Code of Conduct. Project maintainers who do not
|
20
|
+
follow the Code of Conduct may be removed from the project team.
|
21
|
+
|
22
|
+
This code of conduct applies both within project spaces and in public spaces
|
23
|
+
when an individual is representing the project or its community.
|
24
|
+
|
25
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
26
|
+
reported by opening an issue or contacting one or more of the project
|
27
|
+
maintainers.
|
28
|
+
|
29
|
+
This Code of Conduct is adapted from the Contributor Covenant
|
30
|
+
(http://contributor-covenant.org), version 1.1.0, available at
|
31
|
+
http://contributor-covenant.org/version/1/1/0/
|
data/Gemfile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
gem 'bcrypt'
|
5
|
+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
6
|
+
|
7
|
+
if RbConfig::CONFIG["host_os"] =~ /darwin/
|
8
|
+
gem 'terminal-notifier-guard'
|
9
|
+
end
|
10
|
+
|
11
|
+
if ENV['RAILS_SOURCE']
|
12
|
+
gemspec path: ENV['RAILS_SOURCE']
|
13
|
+
else
|
14
|
+
# Need to get rails source beacause the gem doesn't include tests
|
15
|
+
version = ENV['RAILS_VERSION'] || begin
|
16
|
+
require 'net/http'
|
17
|
+
require 'yaml'
|
18
|
+
spec = eval(File.read('activerecord-sqlserver-adapter_new.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']
|
29
|
+
end
|
30
|
+
gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
|
31
|
+
end
|
32
|
+
|
33
|
+
if ENV['AREL']
|
34
|
+
gem 'arel', path: ENV['AREL']
|
35
|
+
end
|
36
|
+
|
37
|
+
group :tinytds do
|
38
|
+
if ENV['TINYTDS_SOURCE']
|
39
|
+
gem 'tiny_tds', path: ENV['TINYTDS_SOURCE']
|
40
|
+
elsif ENV['TINYTDS_VERSION']
|
41
|
+
gem 'tiny_tds', ENV['TINYTDS_VERSION']
|
42
|
+
else
|
43
|
+
gem 'tiny_tds'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
group :odbc do
|
48
|
+
gem 'ruby-odbc'
|
49
|
+
end
|
50
|
+
|
51
|
+
group :development do
|
52
|
+
gem 'mocha'
|
53
|
+
gem 'minitest', '< 5.3.4' # PENDING: [Rails5.x] Remove test order constraint.
|
54
|
+
gem 'minitest-spec-rails'
|
55
|
+
gem 'pry'
|
56
|
+
end
|
57
|
+
|
58
|
+
group :guard do
|
59
|
+
gem 'guard'
|
60
|
+
gem 'guard-minitest'
|
61
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require_relative 'test/support/paths_sqlserver'
|
3
|
+
|
4
|
+
clearing :on
|
5
|
+
notification :terminal_notifier if defined?(TerminalNotifier)
|
6
|
+
ignore %r{debug\.log}
|
7
|
+
|
8
|
+
ar_lib = File.join ARTest::SQLServer.root_activerecord, 'lib'
|
9
|
+
ar_test = File.join ARTest::SQLServer.root_activerecord, 'test'
|
10
|
+
|
11
|
+
guard :minitest, {
|
12
|
+
all_on_start: false,
|
13
|
+
autorun: false,
|
14
|
+
include: ['lib', 'test', ar_lib, ar_test],
|
15
|
+
test_folders: ['test'],
|
16
|
+
test_file_patterns: ["*_test.rb", "*_test_sqlserver.rb"]
|
17
|
+
} do
|
18
|
+
# Our project watchers.
|
19
|
+
if ENV['TEST_FILES']
|
20
|
+
ENV['TEST_FILES'].split(',').map(&:strip).each do |file|
|
21
|
+
watch(%r{.*}) { file }
|
22
|
+
end
|
23
|
+
else
|
24
|
+
watch(%r{^test/cases/\w+_test_sqlserver\.rb$})
|
25
|
+
watch(%r{^test/cases/coerced_tests\.rb$}) { "test/cases/coerced_tests.rb" }
|
26
|
+
watch(%r{^lib/active_record/connection_adapters/sqlserver/([^/]+)\.rb$}) { |m| "test/cases/#{m[1]}_test_sqlserver.rb" }
|
27
|
+
watch(%r{^test/cases/helper_sqlserver\.rb$}) { 'test' }
|
28
|
+
end
|
29
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2015
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
|
2
|
+
# ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
|
3
|
+
|
4
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/mtgbx8f57vr7k2qa/branch/master?svg=true)](https://ci.appveyor.com/project/rails-sqlserver/activerecord-sqlserver-adapter/branch/master) [![Gem Version](http://img.shields.io/gem/v/activerecord-sqlserver-adapter.svg?style=flat)](https://rubygems.org/gems/activerecord-sqlserver-adapter) [![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)
|
5
|
+
|
6
|
+
![kantishna-wide](https://cloud.githubusercontent.com/assets/2381/5895051/aa6a57e0-a4e1-11e4-95b9-23627af5876a.jpg)
|
7
|
+
|
8
|
+
## Code Name Kantishna
|
9
|
+
|
10
|
+
The SQL Server adapter for ActiveRecord v4.2 using SQL Server 2012 or higher.
|
11
|
+
|
12
|
+
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 4.2.x version of the adapter is only for the latest 4.2 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.
|
13
|
+
|
14
|
+
|
15
|
+
#### Executing Stored Procedures
|
16
|
+
|
17
|
+
Every class that sub classes ActiveRecord::Base will now have an execute_procedure class method to use. This method takes the name of the stored procedure which can be a string or symbol and any number of variables to pass to the procedure. Arguments will automatically be quoted per the connection's standards as normal. For example:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
Account.execute_procedure :update_totals, 'admin', nil, true
|
21
|
+
# Or with named parameters.
|
22
|
+
Account.execute_procedure :update_totals, named: 'params'
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
#### Native Data Type Support
|
27
|
+
|
28
|
+
We support every data type supported by FreeTDS and then a few more. All simplified Rails types in migrations will coorespond to a matching SQL Server national (unicode) data type. Here is a basic chart. Always check the `initialize_native_database_types` method for an updated list.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
integer: { name: 'int', limit: 4 }
|
32
|
+
bigint: { name: 'bigint' }
|
33
|
+
boolean: { name: 'bit' }
|
34
|
+
decimal: { name: 'decimal' }
|
35
|
+
money: { name: 'money' }
|
36
|
+
smallmoney: { name: 'smallmoney' }
|
37
|
+
float: { name: 'float' }
|
38
|
+
real: { name: 'real' }
|
39
|
+
date: { name: 'date' }
|
40
|
+
datetime: { name: 'datetime' }
|
41
|
+
datetime2: { name: 'datetime2', precision: 7 }
|
42
|
+
datetimeoffset: { name: 'datetimeoffset', precision: 7 }
|
43
|
+
smalldatetime: { name: 'smalldatetime' }
|
44
|
+
timestamp: { name: 'datetime' }
|
45
|
+
time: { name: 'time' }
|
46
|
+
char: { name: 'char' }
|
47
|
+
varchar: { name: 'varchar', limit: 8000 }
|
48
|
+
varchar_max: { name: 'varchar(max)' }
|
49
|
+
text_basic: { name: 'text' }
|
50
|
+
nchar: { name: 'nchar' }
|
51
|
+
string: { name: 'nvarchar', limit: 4000 }
|
52
|
+
text: { name: 'nvarchar(max)' }
|
53
|
+
ntext: { name: 'ntext' }
|
54
|
+
binary_basic: { name: 'binary' }
|
55
|
+
varbinary: { name: 'varbinary', limit: 8000 }
|
56
|
+
binary: { name: 'varbinary(max)' }
|
57
|
+
uuid: { name: 'uniqueidentifier' }
|
58
|
+
ss_timestamp: { name: 'timestamp' }
|
59
|
+
```
|
60
|
+
|
61
|
+
The following types require TDS version 7.3 with TinyTDS. This requires the latest FreeTDS v0.95 or higher.
|
62
|
+
|
63
|
+
* date
|
64
|
+
* datetime2
|
65
|
+
* datetimeoffset
|
66
|
+
* time
|
67
|
+
|
68
|
+
Set `tds_version` in your database.yml or the `TDSVER` environment variable to `7.3` to ensure you are using the proper protocol version till 7.3 becomes the default.
|
69
|
+
|
70
|
+
**Zone Conversion** - The `[datetimeoffset]` type is the only ActiveRecord time based datatype that does not cast the zone to ActiveRecord's default - typically UTC. As intended, this datatype is meant to maintain the zone you pass to it and/or retreived from the database.
|
71
|
+
|
72
|
+
|
73
|
+
#### Force Schema To Lowercase
|
74
|
+
|
75
|
+
Although it is not necessary, the Ruby convention is to use lowercase method names. If your database schema is in upper or mixed case, we can force all table and column names during the schema reflection process to be lowercase. Add this to your config/initializers file for the adapter.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.lowercase_schema_reflection = true
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
#### Schemas & Users
|
83
|
+
|
84
|
+
Depending on your user and schema setup, it may be needed to use a table name prefix of `dbo.`. So something like this in your initializer file for ActiveRecord or the adapter.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
ActiveRecord::Base.table_name_prefix = 'dbo.'
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
#### Configure Connection & App Name
|
92
|
+
|
93
|
+
We currently conform to an unpublished and non-standard AbstractAdapter interface to configure connections made to the database. To do so, just override the `configure_connection` method in an initializer like so. In this case below we are setting the `TEXTSIZE` to 64 megabytes. Also, TinyTDS supports an application name when it logs into SQL Server. This can be used to identify the connection in SQL Server's activity monitor. By default it will use the `appname` from your database.yml file or a lowercased version of your Rails::Application name. It is now possible to define a `configure_application_name` method that can give you per instance details. Below shows how you might use this to get the process id and thread id of the current connection.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
module ActiveRecord
|
97
|
+
module ConnectionAdapters
|
98
|
+
class SQLServerAdapter < AbstractAdapter
|
99
|
+
|
100
|
+
def configure_connection
|
101
|
+
raw_connection_do "SET TEXTSIZE #{64.megabytes}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def configure_application_name
|
105
|
+
"myapp_#{$$}_#{Thread.current.object_id}".to(29)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
#### Explain Support (SHOWPLAN)
|
114
|
+
|
115
|
+
The 3.2 version of the adapter support ActiveRecord's explain features. In SQL Server, this is called the showplan. By default we use the `SHOWPLAN_ALL` option and format it using a simple table printer. So the following ruby would log the plan table below it.
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
Car.where(id: 1).explain
|
119
|
+
```
|
120
|
+
|
121
|
+
```
|
122
|
+
EXPLAIN for: SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1
|
123
|
+
+----------------------------------------------------+--------+--------+--------+----------------------+----------------------+----------------------------------------------------+----------------------------------------------------+--------------+---------------------+----------------------+------------+---------------------+----------------------------------------------------+----------+----------+----------+--------------------+
|
124
|
+
| StmtText | StmtId | NodeId | Parent | PhysicalOp | LogicalOp | Argument | DefinedValues | EstimateRows | EstimateIO | EstimateCPU | AvgRowSize | TotalSubtreeCost | OutputList | Warnings | Type | Parallel | EstimateExecutions |
|
125
|
+
+----------------------------------------------------+--------+--------+--------+----------------------+----------------------+----------------------------------------------------+----------------------------------------------------+--------------+---------------------+----------------------+------------+---------------------+----------------------------------------------------+----------+----------+----------+--------------------+
|
126
|
+
| SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1 | 1 | 1 | 0 | NULL | NULL | 2 | NULL | 1.0 | NULL | NULL | NULL | 0.00328309996984899 | NULL | NULL | SELECT | false | NULL |
|
127
|
+
| |--Clustered Index Seek(OBJECT:([activerecord... | 1 | 2 | 1 | Clustered Index Seek | Clustered Index Seek | OBJECT:([activerecord_unittest].[dbo].[cars].[P... | [activerecord_unittest].[dbo].[cars].[id], [act... | 1.0 | 0.00312500004656613 | 0.000158099996042438 | 278 | 0.00328309996984899 | [activerecord_unittest].[dbo].[cars].[id], [act... | NULL | PLAN_ROW | false | 1.0 |
|
128
|
+
+----------------------------------------------------+--------+--------+--------+----------------------+----------------------+----------------------------------------------------+----------------------------------------------------+--------------+---------------------+----------------------+------------+---------------------+----------------------------------------------------+----------+----------+----------+--------------------+
|
129
|
+
```
|
130
|
+
|
131
|
+
You can configure a few options to your needs. First is the max column width for the logged table. The default value is 50 characters. You can change it like so.
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
ActiveRecord::ConnectionAdapters::SQLServer::Showplan::PrinterTable.max_column_width = 500
|
135
|
+
```
|
136
|
+
|
137
|
+
Another configuration is the showplan option. Some might find the XML format more useful. If you have Nokogiri installed, we will format the XML string. I will gladly accept pathches that make the XML printer more useful!
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = 'SHOWPLAN_XML'
|
141
|
+
```
|
142
|
+
**NOTE:** The method we utilize to make SHOWPLANs work is very brittle to complex SQL. There is no getting around this as we have to deconstruct an already prepared statement for the sp_executesql method. If you find that explain breaks your app, simple disable it. Do not open a github issue unless you have a patch. Please [consult the Rails guides](http://guides.rubyonrails.org/active_record_querying.html#running-explain) for more info.
|
143
|
+
|
144
|
+
|
145
|
+
## Versions
|
146
|
+
|
147
|
+
The adapter follows a rational versioning policy that also tracks ActiveRecord's major and minor version. That means the latest 3.1.x version of the adapter will always work for the latest 3.1.x version of ActiveRecord.
|
148
|
+
|
149
|
+
|
150
|
+
## Installation
|
151
|
+
|
152
|
+
The adapter has no strict gem dependencies outside of ActiveRecord. You will have to pick a connection mode, the default is dblib which uses the TinyTDS gem. Just bundle the gem and the adapter will use it.
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
gem 'tiny_tds'
|
156
|
+
gem 'activerecord-sqlserver-adapter', '~> 4.2.0'
|
157
|
+
```
|
158
|
+
|
159
|
+
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!
|
160
|
+
|
161
|
+
http://wiki.github.com/rails-sqlserver/activerecord-sqlserver-adapter/platform-installation
|
162
|
+
|
163
|
+
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
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.
|
167
|
+
|
168
|
+
* Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
|
169
|
+
* Gitter: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter
|
170
|
+
|
171
|
+
|
172
|
+
## Credits & Contributions
|
173
|
+
|
174
|
+
Many many people have contributed. If you do not see your name here and it should be let us know. Also, many thanks go out to those that have pledged financial contributions.
|
175
|
+
|
176
|
+
|
177
|
+
## Contributers
|
178
|
+
Up-to-date list of contributors: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/contributors
|
179
|
+
|
180
|
+
* metaskills (Ken Collins)
|
181
|
+
* Annaswims (Annaswims)
|
182
|
+
* wbond (Will Bond)
|
183
|
+
* Thirdshift (Garrett Hart)
|
184
|
+
* h-lame (Murray Steele)
|
185
|
+
* vegantech
|
186
|
+
* cjheath (Clifford Heath)
|
187
|
+
* fryguy (Jason Frey)
|
188
|
+
* jrafanie (Joe Rafaniello)
|
189
|
+
* nerdrew (Andrew Ryan)
|
190
|
+
* snowblink (Jonathan Lim)
|
191
|
+
* koppen (Jakob Skjerning)
|
192
|
+
* ebryn (Erik Bryn)
|
193
|
+
* adzap (Adam Meehan)
|
194
|
+
* neomindryan (Ryan Findley)
|
195
|
+
* jeremydurham (Jeremy Durham)
|
196
|
+
|
197
|
+
|
198
|
+
## License
|
199
|
+
|
200
|
+
Copyright © 2008-2016. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
201
|
+
|