activerecord-sqlserver-adapter 4.1.8 → 4.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -0
  3. data/CHANGELOG.md +60 -0
  4. data/Gemfile +45 -0
  5. data/Guardfile +29 -0
  6. data/MIT-LICENSE +5 -5
  7. data/README.md +193 -0
  8. data/RUNNING_UNIT_TESTS.md +95 -0
  9. data/Rakefile +48 -0
  10. data/activerecord-sqlserver-adapter.gemspec +28 -0
  11. data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +5 -15
  12. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +25 -0
  13. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +6 -4
  14. data/lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb +9 -3
  15. data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +3 -1
  16. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +130 -151
  17. data/lib/active_record/connection_adapters/sqlserver/errors.rb +0 -25
  18. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +39 -78
  19. data/lib/active_record/connection_adapters/sqlserver/schema_cache.rb +71 -47
  20. data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +14 -30
  21. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +112 -108
  22. data/lib/active_record/connection_adapters/sqlserver/showplan.rb +4 -2
  23. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +1 -1
  24. data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +1 -1
  25. data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +52 -7
  26. data/lib/active_record/connection_adapters/sqlserver/transaction.rb +52 -0
  27. data/lib/active_record/connection_adapters/sqlserver/type.rb +46 -0
  28. data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +15 -0
  29. data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +15 -0
  30. data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +13 -0
  31. data/lib/active_record/connection_adapters/sqlserver/type/castable.rb +15 -0
  32. data/lib/active_record/connection_adapters/sqlserver/type/char.rb +15 -0
  33. data/lib/active_record/connection_adapters/sqlserver/type/core_ext/value.rb +39 -0
  34. data/lib/active_record/connection_adapters/sqlserver/type/date.rb +14 -0
  35. data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +37 -0
  36. data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +13 -0
  37. data/lib/active_record/connection_adapters/sqlserver/type/float.rb +17 -0
  38. data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +13 -0
  39. data/lib/active_record/connection_adapters/sqlserver/type/money.rb +21 -0
  40. data/lib/active_record/connection_adapters/sqlserver/type/quoter.rb +32 -0
  41. data/lib/active_record/connection_adapters/sqlserver/type/real.rb +17 -0
  42. data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +13 -0
  43. data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +21 -0
  44. data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +24 -0
  45. data/lib/active_record/connection_adapters/sqlserver/type/string.rb +12 -0
  46. data/lib/active_record/connection_adapters/sqlserver/type/text.rb +15 -0
  47. data/lib/active_record/connection_adapters/sqlserver/type/time.rb +59 -0
  48. data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +15 -0
  49. data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +22 -0
  50. data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +15 -0
  51. data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +12 -0
  52. data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +15 -0
  53. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +20 -0
  54. data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +20 -0
  55. data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +23 -0
  56. data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +20 -0
  57. data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +20 -0
  58. data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +20 -0
  59. data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +20 -0
  60. data/lib/active_record/connection_adapters/sqlserver/utils.rb +118 -12
  61. data/lib/active_record/connection_adapters/sqlserver/version.rb +11 -0
  62. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +133 -198
  63. data/lib/active_record/connection_adapters/sqlserver_column.rb +15 -86
  64. data/lib/active_record/sqlserver_base.rb +2 -0
  65. data/lib/arel/visitors/sqlserver.rb +120 -393
  66. data/lib/{arel/arel_sqlserver.rb → arel_sqlserver.rb} +1 -3
  67. data/test/cases/adapter_test_sqlserver.rb +420 -0
  68. data/test/cases/coerced_tests.rb +642 -0
  69. data/test/cases/column_test_sqlserver.rb +703 -0
  70. data/test/cases/connection_test_sqlserver.rb +216 -0
  71. data/test/cases/database_statements_test_sqlserver.rb +57 -0
  72. data/test/cases/execute_procedure_test_sqlserver.rb +38 -0
  73. data/test/cases/helper_sqlserver.rb +36 -0
  74. data/test/cases/migration_test_sqlserver.rb +66 -0
  75. data/test/cases/order_test_sqlserver.rb +147 -0
  76. data/test/cases/pessimistic_locking_test_sqlserver.rb +90 -0
  77. data/test/cases/schema_dumper_test_sqlserver.rb +175 -0
  78. data/test/cases/schema_test_sqlserver.rb +54 -0
  79. data/test/cases/scratchpad_test_sqlserver.rb +9 -0
  80. data/test/cases/showplan_test_sqlserver.rb +65 -0
  81. data/test/cases/specific_schema_test_sqlserver.rb +118 -0
  82. data/test/cases/transaction_test_sqlserver.rb +61 -0
  83. data/test/cases/utils_test_sqlserver.rb +91 -0
  84. data/test/cases/uuid_test_sqlserver.rb +41 -0
  85. data/test/config.yml +35 -0
  86. data/test/fixtures/1px.gif +0 -0
  87. data/test/migrations/transaction_table/1_table_will_never_be_created.rb +11 -0
  88. data/test/models/sqlserver/customers_view.rb +3 -0
  89. data/test/models/sqlserver/datatype.rb +3 -0
  90. data/test/models/sqlserver/datatype_migration.rb +3 -0
  91. data/test/models/sqlserver/dollar_table_name.rb +3 -0
  92. data/test/models/sqlserver/edge_schema.rb +13 -0
  93. data/test/models/sqlserver/fk_has_fk.rb +3 -0
  94. data/test/models/sqlserver/fk_has_pk.rb +3 -0
  95. data/test/models/sqlserver/natural_pk_data.rb +4 -0
  96. data/test/models/sqlserver/natural_pk_int_data.rb +3 -0
  97. data/test/models/sqlserver/no_pk_data.rb +3 -0
  98. data/test/models/sqlserver/quoted_table.rb +7 -0
  99. data/test/models/sqlserver/quoted_view_1.rb +3 -0
  100. data/test/models/sqlserver/quoted_view_2.rb +3 -0
  101. data/test/models/sqlserver/string_default.rb +3 -0
  102. data/test/models/sqlserver/string_defaults_big_view.rb +3 -0
  103. data/test/models/sqlserver/string_defaults_view.rb +3 -0
  104. data/test/models/sqlserver/tinyint_pk.rb +3 -0
  105. data/test/models/sqlserver/upper.rb +3 -0
  106. data/test/models/sqlserver/uppered.rb +3 -0
  107. data/test/models/sqlserver/uuid.rb +3 -0
  108. data/test/schema/datatypes/2012.sql +64 -0
  109. data/test/schema/sqlserver_specific_schema.rb +181 -0
  110. data/test/support/coerceable_test_sqlserver.rb +45 -0
  111. data/test/support/load_schema_sqlserver.rb +29 -0
  112. data/test/support/minitest_sqlserver.rb +1 -0
  113. data/test/support/paths_sqlserver.rb +48 -0
  114. data/test/support/rake_helpers.rb +41 -0
  115. data/test/support/sql_counter_sqlserver.rb +32 -0
  116. metadata +271 -21
  117. data/CHANGELOG +0 -39
  118. data/VERSION +0 -1
  119. data/lib/active_record/connection_adapters/sqlserver/core_ext/relation.rb +0 -17
  120. data/lib/active_record/sqlserver_test_case.rb +0 -17
  121. data/lib/arel/nodes_sqlserver.rb +0 -14
  122. data/lib/arel/select_manager_sqlserver.rb +0 -62
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6738a943e243e64280e1fade7fc29860c8636816
4
- data.tar.gz: c658b0ba20835d87f42398f680fccca5e0fcf716
3
+ metadata.gz: 4761029202d3adf1b562330d1931f922e8310897
4
+ data.tar.gz: 7476ee98b07671b29729e87265a0b3f77e573af6
5
5
  SHA512:
6
- metadata.gz: faaf430a3992e4910a8c3b4b8f1254ff3c0f46469ee9a5a68c616976366d8725f53afd21173e359e367999348e4f570599f9b8286f07f6a0b3f15094f5662002
7
- data.tar.gz: a7c9a880f68ea2f90e0e28d74e5acd95ed5bc17562afee82e1d0cd5742671be64a39159bb282100a792e6b85b3d4bb593bb6dd2bcb7516cd430784646d8c2133
6
+ metadata.gz: d8a5024c099b455c09abdeeb00469f7d3a397943897ea25d1f225221c51bcc5ccd329b059746e8c6972dd4cd0456aa16d581b67c6c7d74a84f1a5d6cc2706f79
7
+ data.tar.gz: eeb7cbf4bcc2972682e0bbe653a1ccfd4b50251f85e1b595551de4142403be72247633441e63622da7658c1540da6472c0130f769ddbf1b63bf267ba7b4218fc
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ nbproject/
2
+ debug.log
3
+ .DS_Store
4
+ pkg/
5
+ doc/
6
+ *.gem
7
+ .bundle
8
+ Gemfile.lock
9
+ test/profile/output/*
10
+ .rvmrc
11
+ .rbenv-version
12
+ .idea
13
+ coverage/*
14
+ .flooignore
15
+ .floo
data/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+
2
+ ## v4.2.0
3
+
4
+ #### Added
5
+
6
+ * New `ActiveRecord::Type` objects. See `active_record/connection_adapters/sqlserver/type` dir.
7
+ * Aliased `ActiveRecord::Type::SQLServer` to `ActiveRecord::ConnectionAdapters::SQLServer::Type`
8
+ * New `SQLServer::Utils::Name` object for decomposing and quoting SQL Server names/identifiers.
9
+ * Support for most all SQL Server types in schema statements and dumping.
10
+ * Support create table with query from relation or select statement.
11
+
12
+ #### Changed
13
+
14
+ * The `create_database` now takes an options hash. Only key/value now is `collation`. Unknown keys just use raw values for SQL.
15
+ * Complete rewrite of our Arel visitor. Focuing on 2012 and upward so we can make FETCH happen.
16
+ * Testing enhancements.
17
+ * Guard support, check our Guardfile.
18
+ * Use `ARTest` namespace with `SQLServer` module for our helpers/objects.
19
+ * Simple 2012 schmea addition and extensive column/type_cast object tests.
20
+ * Follow Rails convention and remove varying character default limits.
21
+ * The `cs_equality_operator` is now s class configuration property only.
22
+ * The `with_identity_insert_enabled(table_name)` is now public.
23
+ * Use ActiveRecord tranasaction interface vs our own `run_with_isolation_level`.
24
+ * Turn on bulk `supports_bulk_alter?`.
25
+
26
+ #### Deprecated
27
+
28
+ * n/a
29
+
30
+ #### Removed
31
+
32
+ * SQL Server versions < 2012 which do not support OFFSET and FETCH. http://bit.ly/1B5Bwsd
33
+ * The `enable_default_unicode_types` option. Default to national types all the time.
34
+ * Native type configs for older DB support. Includes the following with new default value:
35
+ * native_string_database_type => `nvarchar`
36
+ * native_text_database_type => `nvarchar(max)`
37
+ * native_binary_database_type => `varbinary(max)`
38
+ * Various version and inspection methods removed. These include:
39
+ * database_version
40
+ * database_year
41
+ * product_level
42
+ * product_version
43
+ * edition
44
+ * Removed tests for old issue #164. Handled by core types now.
45
+ * The `activity_stats` method. Please put this in a gem if needed.
46
+ * We no longer use regular expressions to fix identity inserts. Use ActiveRecord or public ID insert helper.
47
+ * All auto reconnect and SQL retry logic. Got too complicated and stood in the way of AR's pool. Speed boost too.
48
+ * The adapter will no longer try to remove duplicate order by clauses. Use relation `reorder`, `unscope`, etc.
49
+ * We no longer use regular expressions to remove identity columns from updates. Now with `attributes_for_update` AR hook.
50
+
51
+ #### Fixed
52
+
53
+ * Default lock is now "WITH(UPDLOCK)". Fixes #368
54
+ * Better bind types & params for `sp_executesql`. Fixes #239.
55
+
56
+ #### Security
57
+
58
+ * The connection's `inspect` method no longer returns sensitive connection info. Very basic now.
59
+
60
+
data/Gemfile ADDED
@@ -0,0 +1,45 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'bcrypt'
5
+
6
+ if RbConfig::CONFIG["host_os"] =~ /darwin/
7
+ gem 'terminal-notifier-guard'
8
+ end
9
+
10
+ if ENV['RAILS_SOURCE']
11
+ gemspec path: ENV['RAILS_SOURCE']
12
+ else
13
+ # Need to get rails source beacause the gem doesn't include tests
14
+ version = ENV['RAILS_VERSION'] || begin
15
+ require 'net/http'
16
+ require 'yaml'
17
+ spec = eval(File.read('activerecord-sqlserver-adapter.gemspec'))
18
+ version = spec.dependencies.detect{ |d|d.name == 'activerecord' }.requirement.requirements.first.last.version
19
+ major, minor, tiny = version.split('.')
20
+ uri = URI.parse "http://rubygems.org/api/v1/versions/activerecord.yaml"
21
+ YAML.load(Net::HTTP.get(uri)).select do |data|
22
+ a, b, c = data['number'].split('.')
23
+ !data['prerelease'] && major == a && (minor.nil? || minor == b)
24
+ end.first['number']
25
+ end
26
+ gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
27
+ end
28
+
29
+ if ENV['AREL']
30
+ gem 'arel', path: ENV['AREL']
31
+ end
32
+
33
+ group :tinytds do
34
+ if ENV['TINYTDS_SOURCE']
35
+ gem 'tiny_tds', path: ENV['TINYTDS_SOURCE']
36
+ else
37
+ # TODO: [Rails4] Change back... segfault caused by tiny_tds 0.6.1
38
+ gem 'tiny_tds', git:"https://github.com/rails-sqlserver/tiny_tds.git"
39
+ end
40
+ end
41
+
42
+ group :odbc do
43
+ gem 'ruby-odbc'
44
+ end
45
+
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 CHANGED
@@ -1,5 +1,5 @@
1
- Copyright (c) 2008-2011
2
-
1
+ Copyright (c) 2008-2015
2
+
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
5
5
  "Software"), to deal in the Software without restriction, including
@@ -7,14 +7,14 @@ without limitation the rights to use, copy, modify, merge, publish,
7
7
  distribute, sublicense, and/or sell copies of the Software, and to
8
8
  permit persons to whom the Software is furnished to do so, subject to
9
9
  the following conditions:
10
-
10
+
11
11
  The above copyright notice and this permission notice shall be
12
12
  included in all copies or substantial portions of the Software.
13
-
13
+
14
14
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
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.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,193 @@
1
+
2
+ # ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
3
+
4
+ [![Gem Version](http://img.shields.io/gem/v/activerecord-sqlserver-adapter.svg?style=flat)](https://rubygems.org/gems/activerecord-sqlserver-adapter)
5
+ [![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)
6
+
7
+ ![kantishna-wide](https://cloud.githubusercontent.com/assets/2381/5895051/aa6a57e0-a4e1-11e4-95b9-23627af5876a.jpg)
8
+
9
+ ## Code Name Kantishna
10
+
11
+ The SQL Server adapter for ActiveRecord. 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. We follow a rational versioning policy that tracks ActiveRecord. That means that our 4.2.x version of the adapter is only for the latest 4.2 version of Rails. We also have stable branches for each major/minor release of ActiveRecord.
12
+
13
+
14
+ #### Testing Rake Tasks Support
15
+
16
+ This is a long story, but if you are not working with a legacy database and you can trust your schema.rb to setup your local development or test database, then we have adapter level support for rails :db rake tasks. Please read this wiki page for full details.
17
+
18
+ http://wiki.github.com/rails-sqlserver/activerecord-sqlserver-adapter/rails-db-rake-tasks
19
+
20
+
21
+ #### Executing Stored Procedures
22
+
23
+ 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:
24
+
25
+ ```ruby
26
+ Account.execute_procedure :update_totals, 'admin', nil, true
27
+ # Or with named parameters.
28
+ Account.execute_procedure :update_totals, named: 'params'
29
+ ```
30
+
31
+
32
+ #### Native Data Type Support
33
+
34
+ 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 data type. Here is a basic chart. Always check the `initialize_native_database_types` method for an updated list.
35
+
36
+ ```ruby
37
+ integer: { name: 'int', limit: 4 }
38
+ bigint: { name: 'bigint' }
39
+ boolean: { name: 'bit' }
40
+ decimal: { name: 'decimal' }
41
+ money: { name: 'money' }
42
+ smallmoney: { name: 'smallmoney' }
43
+ float: { name: 'float' }
44
+ real: { name: 'real' }
45
+ date: { name: 'date' }
46
+ datetime: { name: 'datetime' }
47
+ timestamp: { name: 'datetime' }
48
+ time: { name: 'time' }
49
+ char: { name: 'char' }
50
+ varchar: { name: 'varchar', limit: 8000 }
51
+ varchar_max: { name: 'varchar(max)' }
52
+ text_basic: { name: 'text' }
53
+ nchar: { name: 'nchar' }
54
+ string: { name: 'nvarchar', limit: 4000 }
55
+ text: { name: 'nvarchar(max)' }
56
+ ntext: { name: 'ntext' }
57
+ binary_basic: { name: 'binary' }
58
+ varbinary: { name: 'varbinary', limit: 8000 }
59
+ binary: { name: 'varbinary(max)' }
60
+ uuid: { name: 'uniqueidentifier' }
61
+ ss_timestamp: { name: 'timestamp' }
62
+ ```
63
+
64
+
65
+ #### Force Schema To Lowercase
66
+
67
+ 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.
68
+
69
+ ```ruby
70
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.lowercase_schema_reflection = true
71
+ ```
72
+
73
+
74
+ #### Schemas & Users
75
+
76
+ 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.
77
+
78
+ ```ruby
79
+ ActiveRecord::Base.table_name_prefix = 'dbo.'
80
+ ```
81
+
82
+
83
+ #### Configure Connection & App Name
84
+
85
+ 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.
86
+
87
+ ```ruby
88
+ module ActiveRecord
89
+ module ConnectionAdapters
90
+ class SQLServerAdapter < AbstractAdapter
91
+
92
+ def configure_connection
93
+ raw_connection_do "SET TEXTSIZE #{64.megabytes}"
94
+ end
95
+
96
+ def configure_application_name
97
+ "myapp_#{$$}_#{Thread.current.object_id}".to(29)
98
+ end
99
+
100
+ end
101
+ end
102
+ end
103
+ ```
104
+
105
+ #### Explain Support (SHOWPLAN)
106
+
107
+ 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.
108
+
109
+ ```ruby
110
+ Car.where(id: 1).explain
111
+ ```
112
+
113
+ ```
114
+ EXPLAIN for: SELECT [cars].* FROM [cars] WHERE [cars].[id] = 1
115
+ +----------------------------------------------------+--------+--------+--------+----------------------+----------------------+----------------------------------------------------+----------------------------------------------------+--------------+---------------------+----------------------+------------+---------------------+----------------------------------------------------+----------+----------+----------+--------------------+
116
+ | StmtText | StmtId | NodeId | Parent | PhysicalOp | LogicalOp | Argument | DefinedValues | EstimateRows | EstimateIO | EstimateCPU | AvgRowSize | TotalSubtreeCost | OutputList | Warnings | Type | Parallel | EstimateExecutions |
117
+ +----------------------------------------------------+--------+--------+--------+----------------------+----------------------+----------------------------------------------------+----------------------------------------------------+--------------+---------------------+----------------------+------------+---------------------+----------------------------------------------------+----------+----------+----------+--------------------+
118
+ | 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 |
119
+ | |--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 |
120
+ +----------------------------------------------------+--------+--------+--------+----------------------+----------------------+----------------------------------------------------+----------------------------------------------------+--------------+---------------------+----------------------+------------+---------------------+----------------------------------------------------+----------+----------+----------+--------------------+
121
+ ```
122
+
123
+ 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.
124
+
125
+ ```ruby
126
+ ActiveRecord::ConnectionAdapters::SQLServer::Showplan::PrinterTable.max_column_width = 500
127
+ ```
128
+
129
+ 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!
130
+
131
+ ```ruby
132
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.showplan_option = 'SHOWPLAN_XML'
133
+ ```
134
+ **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.
135
+
136
+
137
+ ## Versions
138
+
139
+ 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.
140
+
141
+
142
+ ## Installation
143
+
144
+ 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.
145
+
146
+ ```ruby
147
+ gem 'tiny_tds'
148
+ gem 'activerecord-sqlserver-adapter', '~> 4.2.0'
149
+ ```
150
+
151
+ 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!
152
+
153
+ http://wiki.github.com/rails-sqlserver/activerecord-sqlserver-adapter/platform-installation
154
+
155
+
156
+ ## Contributing
157
+
158
+ 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.
159
+
160
+ * Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
161
+ * Gitter: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter
162
+
163
+
164
+ ## Credits & Contributions
165
+
166
+ 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.
167
+
168
+
169
+ ## Contributers
170
+ Up-to-date list of contributors: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/contributors
171
+
172
+ * metaskills (Ken Collins)
173
+ * Annaswims (Annaswims)
174
+ * wbond (Will Bond)
175
+ * Thirdshift (Garrett Hart)
176
+ * h-lame (Murray Steele)
177
+ * vegantech
178
+ * cjheath (Clifford Heath)
179
+ * fryguy (Jason Frey)
180
+ * jrafanie (Joe Rafaniello)
181
+ * nerdrew (Andrew Ryan)
182
+ * snowblink (Jonathan Lim)
183
+ * koppen (Jakob Skjerning)
184
+ * ebryn (Erik Bryn)
185
+ * adzap (Adam Meehan)
186
+ * neomindryan (Ryan Findley)
187
+ * jeremydurham (Jeremy Durham)
188
+
189
+
190
+ ## License
191
+
192
+ Copyright © 2008-2015. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
193
+
@@ -0,0 +1,95 @@
1
+
2
+ # How To Run The Test!
3
+
4
+ This process is much easier than it has been before!
5
+
6
+
7
+ ## TL;DR
8
+
9
+ Default testing uses DBLIB with TinyTDS.
10
+
11
+ * Setup two databases in SQL Server, [activerecord_unittest] and [activerecord_unittest2]
12
+ * Create a [rails] user with an empty password and give it a [db_owner] role to both DBs. Some tests require a server role of [sysadmin] too.
13
+ - http://twitpic.com/9bsiyp/full
14
+ - http://twitpic.com/9bsj7z/full
15
+ - http://twitpic.com/9bsjdx/full
16
+ - http://twitpic.com/9bsjl7/full
17
+ * $ bundle install
18
+ * $ bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'
19
+
20
+
21
+ ## Creating the test databases
22
+
23
+ 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.
24
+
25
+ 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.
26
+
27
+
28
+ ## Cloning The Repos
29
+
30
+ The tests of this adapter depend on the existence of the Rails which are automatically cloned for you with bundler. However you can clone Rails from git://github.com/rails/rails.git and set the `RAILS_SOURCE` environment variable so bundler will use another local path instead.
31
+
32
+ ```
33
+ $ git clone git://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git
34
+ ```
35
+
36
+ Suggest just letting bundler do all the work and assuming there is a git tag for the Rails version, you can set `RAILS_VERSION` before bundling.
37
+
38
+ ```
39
+ $ export RAILS_VERSION='4.2.0'
40
+ $ bundle install
41
+ ```
42
+
43
+
44
+ ## Configure DB Connection
45
+
46
+ Please consult the `test/config.yml` file which is used to parse the configuration options for the DB connections when running tests. This file has overrides for any connection mode that you can set using simple environment variables. Assuming you are using FreeTDS 0.91 and above
47
+
48
+ ```
49
+ $ export ACTIVERECORD_UNITTEST_HOST='my.db.net' # Defaults to localhost
50
+ $ export ACTIVERECORD_UNITTEST_PORT='1533' # Defaults to 1433
51
+ ```
52
+
53
+ If you have FreeTDS installed and/or want to use a named dataserver in your freetds.conf file
54
+
55
+ ```
56
+ $ export ACTIVERECORD_UNITTEST_DATASERVER='mydbname'
57
+ ```
58
+
59
+ These can be passed down to rake too.
60
+
61
+ ```
62
+ $ bundle exec rake test ACTIVERECORD_UNITTEST_HOST='my.db.net'
63
+ ```
64
+
65
+
66
+ ## Bundling
67
+
68
+ Now with that out of the way you can run "bundle install" to hook everything up. Our tests use bundler to setup the load paths correctly. The default mode is DBLIB using TinyTDS. It is important to use bundle exec so we can wire up the ActiveRecord test libs correctly.
69
+
70
+ ```
71
+ $ bundle exec rake test
72
+ ```
73
+
74
+
75
+ ## Testing Options
76
+
77
+ 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.
78
+
79
+ ```
80
+ $ bundle install --without odbc
81
+ ```
82
+
83
+ You can run different connection modes using the following rake commands. Again, the DBLIB connection mode using TinyTDS is the default test task.
84
+
85
+ ```
86
+ $ bundle exec rake test:dblib
87
+ $ bundle exec rake test:odbc
88
+ ```
89
+
90
+ 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.
91
+
92
+
93
+ ## Current Expected Failures
94
+
95
+ * Misc Date/Time erros when using ODBC mode.