activerecord-sqlserver-adapter 2.3.24 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGELOG +5 -108
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +33 -61
  4. data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +57 -0
  5. data/lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb +57 -0
  6. data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +49 -0
  7. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +336 -0
  8. data/lib/active_record/connection_adapters/sqlserver/errors.rb +33 -0
  9. data/lib/active_record/connection_adapters/sqlserver/query_cache.rb +17 -0
  10. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +61 -0
  11. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +373 -0
  12. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +131 -1121
  13. data/lib/arel/engines/sql/compilers/sqlserver_compiler.rb +267 -0
  14. metadata +26 -76
  15. data/RUNNING_UNIT_TESTS +0 -31
  16. data/Rakefile +0 -60
  17. data/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb +0 -151
  18. data/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/odbc.rb +0 -40
  19. data/test/cases/aaaa_create_tables_test_sqlserver.rb +0 -19
  20. data/test/cases/adapter_test_sqlserver.rb +0 -755
  21. data/test/cases/attribute_methods_test_sqlserver.rb +0 -33
  22. data/test/cases/basics_test_sqlserver.rb +0 -86
  23. data/test/cases/calculations_test_sqlserver.rb +0 -20
  24. data/test/cases/column_test_sqlserver.rb +0 -354
  25. data/test/cases/connection_test_sqlserver.rb +0 -148
  26. data/test/cases/eager_association_test_sqlserver.rb +0 -42
  27. data/test/cases/execute_procedure_test_sqlserver.rb +0 -35
  28. data/test/cases/inheritance_test_sqlserver.rb +0 -28
  29. data/test/cases/method_scoping_test_sqlserver.rb +0 -28
  30. data/test/cases/migration_test_sqlserver.rb +0 -108
  31. data/test/cases/named_scope_test_sqlserver.rb +0 -21
  32. data/test/cases/offset_and_limit_test_sqlserver.rb +0 -108
  33. data/test/cases/pessimistic_locking_test_sqlserver.rb +0 -125
  34. data/test/cases/query_cache_test_sqlserver.rb +0 -24
  35. data/test/cases/schema_dumper_test_sqlserver.rb +0 -72
  36. data/test/cases/specific_schema_test_sqlserver.rb +0 -154
  37. data/test/cases/sqlserver_helper.rb +0 -140
  38. data/test/cases/table_name_test_sqlserver.rb +0 -38
  39. data/test/cases/transaction_test_sqlserver.rb +0 -93
  40. data/test/cases/unicode_test_sqlserver.rb +0 -54
  41. data/test/cases/validations_test_sqlserver.rb +0 -18
  42. data/test/connections/native_sqlserver/connection.rb +0 -26
  43. data/test/connections/native_sqlserver_odbc/connection.rb +0 -28
  44. data/test/migrations/transaction_table/1_table_will_never_be_created.rb +0 -11
  45. data/test/schema/sqlserver_specific_schema.rb +0 -113
data/CHANGELOG CHANGED
@@ -1,112 +1,9 @@
1
1
 
2
- * 2.3.24 *
2
+ MASTER
3
3
 
4
- * Create a #configure_application_name method that can be overridden for unique TinyTDS app names
5
- to show up in SQL Server's activity monitor.
4
+ * 3.0.0
6
5
 
7
-
8
- * 2.3.23 *
9
-
10
- * Create a #configure_connection method that can be overridden. Think "SET TEXTSIZE...".
11
-
12
- * Fixed the #finish_statement_handle to cancel the TinyTDS connection if needed.
13
-
14
- * Fix the #indexes method to fail gracefully if sp_helptext permissions fail.
15
-
16
-
17
- * 2.3.22 *
18
-
19
- * Make #rollback_db_transaction smarter.
20
-
21
-
22
- * 2.3.21 *
23
-
24
- * Add support/test around handling of float/real column types [Lucas Maxwell]
25
-
26
-
27
- * 2.3.20 *
28
-
29
- * Fixes quote column names and passes tests for ActiveRecord 2.3.14.
30
-
31
-
32
- * 2.3.19 *
33
-
34
- * Allow drop_database to be called even when DB does not exist.
35
-
36
-
37
- * 2.3.18 *
38
-
39
- * Warn of possible permission problems if "EXEC sp_helptext..." does not work view. Fixes #73.
40
-
41
- * Fix returning of auto-increment identity for TinyTDS driver. [Gregory McIntyre / puyo]
42
-
43
-
44
- * 2.3.17 *
45
-
46
- * Allow TinyTDS/DBLIB mode to pass down :host/:port config options.
47
-
48
-
49
- * 2.3.16 *
50
-
51
- * TinyTDS enhancements for lost connections. Default connection mode.
52
-
53
-
54
- * 2.3.15 *
55
-
56
- * Version bump due to bad 2.3.14 release.
57
-
58
-
59
- * 2.3.14 *
60
-
61
- * Flatten sp_helpconstraint when looking for constraints just in case fks are present. Issue #64.
62
-
63
- * Properly quote table names when reflecting on views.
64
-
65
- * Add "dead or not enabled" to :dblib's lost connection messages.
66
-
67
-
68
- * 2.3.13 *
69
-
70
- * Fixed native database type memoization, now at connection instance level. Fix #execute_procedure for :dblib mode to return indifferent access rows too. Misc test case fixes for 2000 & 2005 need for using coerced Time vs Date type. Fix SQL Server 2000's lack of using TinyTds' native affected rows for UPDATE statements, revert to raw SQL.
71
-
72
- * Make login timeout and query timeout backward database.yml friendly for :dblib mode.
73
-
74
-
75
- * 2.3.12 *
76
-
77
- * Add multiple results set support with #execute_procedure for :dblib mode. [Ken Collins]
78
-
79
- * Allow unicode conditions strings to be quoted correctly. Like 3.0 branch. [Ken Collins]
80
-
81
- * Simplify encoding support. [Ken Collins]
82
-
83
- * Add binary timestamp datatype handling. [Erik Bryn]
84
-
85
-
86
- * 2.3.11
87
-
88
- * Add TinyTds/dblib connection mode. [Ken Collins]
89
-
90
-
91
- * 2.3.10
92
-
93
- * Fix DSN'less code. [Erik Bryn]
94
-
95
-
96
- * 2.3.9
97
-
98
- * Support DSN'less connections. Resolves ticket 38.
99
-
100
- * Support upcoming ruby odbc 0.99992
101
-
102
- * Include new raw connection interfaces developed and optimized under the 3.0 branch.
103
-
104
- * The remove_column conforms to ArgumentError exceptions. [Ken Collins]
105
-
106
- * Add support for default function values in schema reflection. Allows for uniqueidentifier default
107
- values like NEWID(). These are not automatically inserted into the INSERT statement as of yet, that
108
- could be done user side on a before save callback now. Includes new #newid_function and
109
- #newsequentialid_function on the connection for helping. Resolves tikcet #42. [Ken Collins]
6
+ * Release rails 3 version!
110
7
 
111
8
 
112
9
  * 2.3.8
@@ -123,7 +20,7 @@ could be done user side on a before save callback now. Includes new #newid_funct
123
20
 
124
21
  * Allow DNS's to not contain a database and use what is in database.yml [Marco Mastrodonato]
125
22
 
126
- * Rake tasks methods for vanallia rails :db namespace parity. [Ken Collins]
23
+ * Rake tasks methods for vanilla rails :db namespace parity. [Ken Collins]
127
24
 
128
25
  * IronRuby integrated security fixes [Jimmy Schementi]
129
26
 
@@ -148,7 +45,7 @@ could be done user side on a before save callback now. Includes new #newid_funct
148
45
 
149
46
  * Qualify INFORMATION_SCHEMA.COLUMNS with a correct period DB name if present.
150
47
 
151
- * Allow adapter to return multipe results sets, for example from stored procedures. [Chris Hall]
48
+ * Allow adapter to return multiple results sets, for example from stored procedures. [Chris Hall]
152
49
 
153
50
 
154
51
  * 2.3.4
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008
1
+ Copyright (c) 2008-2010
2
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
@@ -1,54 +1,32 @@
1
1
 
2
- == Rails SQL Server 2000, 2005 and 2008 Adapter
2
+ == SQL Server 2005 and 2008 Adapter For ActiveRecord
3
3
 
4
- The SQL Server adapter for rails is back for ActiveRecord 2.2 and up! We are currently passing all tests and hope to continue to do so moving forward.
4
+ The SQL Server adapter for ActiveRecord.
5
5
 
6
6
 
7
7
  == What's New
8
8
 
9
- * New dblib connection mode using TinyTds!
10
- * Integration with rails :db namespaced rake tasks.
11
- * IronRuby support using ADONET connection mode.
12
- * Direct ODBC mode. No DBI anymore, means around 20% faster!
13
- * Now supports SQL Server 2008 too!
14
- * Fully tested under 1.9!!! Correctly encodes/decodes UTF-8 types in ruby 1.9 too.
15
- * Now supports both rails 2.2 & 2.3!!!
16
- * An ActiveRecord::Base.execute_procedure method that can be used by classes.
17
- * Enabled support for DDL transactions.
18
- * Micro second support. Time#usec is automatically converted to SQL Server's 3.33 millisecond limitation.
19
- * Datetime data types before type casting are represented correctly. For example: 1998-01-01 23:59:59.997
20
- * Implementation for #disable_referential_integrity used by ActiveRecord's Fixtures class.
21
- * Pessimistic locking suppot. See the #add_lock! method for details.
22
- * Enabled #case_sensitive_equality_operator used by unique validations.
23
- * Unicode character support for nchar, nvarchar and ntext data types. Configuration option for defaulting all string data types to the unicode safe types.
24
- * View support for table names, identity inserts, and column defaults.
25
- * A block method to run queries within a specific isolation level.
26
- * Automatically reconnects to lost database connections.
9
+ * Version 3.x now supports rails 3!
27
10
 
28
11
 
29
12
  ==== Testing Rake Tasks Support
30
13
 
31
14
  This is a long story, but if you are not working with a legacy database and you can trust your schema.rb to setup you local development or test database, then we have adapter level support for rails :db rake tasks. Please read this wiki page for full details.
32
15
 
33
- http://wiki.github.com/rails-sqlserver/2000-2005-adapter/rails-db-rake-tasks
34
-
35
-
36
- ==== SQL Server 2008 Support
37
-
38
- Because this adapter is primarily coded to SQL Server 2000/2005, it does not take advantage of many of the things in 2008 that would speed up the code. At some point in the future there will be a branch of this code that is specifically targeted for 2008. That adapter version will remove much of the dirty innards of this version that are meant to code around many previous SQL Server 2000/2005 short comings, the biggest being no limit/offset.
39
-
16
+ http://wiki.github.com/rails-sqlserver/activerecord-sqlserver-adapter/rails-db-rake-tasks
40
17
 
41
18
 
42
19
  ==== Date/Time Data Type Hinting
43
20
 
44
- Both SQL Server 2000 and 2005 do not include native data types for just 'date' or 'time', it only has 'datetime'. To pass the ActiveRecord tests we implemented two simple class methods that can teach your models to coerce column information to be cast correctly. Simply past a list of symbols to either the <tt>coerce_sqlserver_date</tt> or <tt>coerce_sqlserver_time</tt> methods that correspond to 'datetime' columns that need to be cast correctly.
21
+ SQL Server 2005 does not include a native data type for just 'date' or 'time', it only has 'datetime'. To pass the ActiveRecord tests we implemented two simple class methods that can teach your models to coerce column information to be cast correctly. Simply pass a list of symbols to either the <tt>coerce_sqlserver_date</tt> or <tt>coerce_sqlserver_time</tt> methods that correspond to 'datetime' columns that need to be cast correctly.
45
22
 
46
23
  class Topic < ActiveRecord::Base
47
24
  coerce_sqlserver_date :last_read
48
25
  coerce_sqlserver_time :bonus_time
49
26
  end
50
27
 
51
- This implementation has some limitations. To date we can only coerce date/time types for models that conform to the expected ActiveRecord class to table naming convention. So a table of 'foo_bar_widgets' will look for coerced types in the FooBarWidget class if it exists.
28
+ This implementation has some limitations. To date we can only coerce date/time types for models that conform to the expected ActiveRecord class to table naming conventions. So a table of 'foo_bar_widgets' will look for coerced column types in the FooBarWidget class.
29
+
52
30
 
53
31
  ==== Executing Stored Procedures
54
32
 
@@ -56,6 +34,7 @@ Every class that sub classes ActiveRecord::Base will now have an execute_procedu
56
34
 
57
35
  Account.execute_procedure :update_totals, 'admin', nil, true
58
36
 
37
+
59
38
  ==== Native Data Type Support
60
39
 
61
40
  Currently the following custom data types have been tested for schema definitions.
@@ -64,8 +43,8 @@ Currently the following custom data types have been tested for schema definition
64
43
  * nchar
65
44
  * nvarchar
66
45
  * ntext
67
- * varchar(max) for SQL Server 2005 only.
68
- * nvarchar(max) for SQL Server 2005 only.
46
+ * varchar(max)
47
+ * nvarchar(max)
69
48
 
70
49
  For example:
71
50
 
@@ -78,41 +57,30 @@ For example:
78
57
  t.column :body2_utf8, :nvarchar_max # Creates nvarchar(max)
79
58
  end
80
59
 
81
- Manually creating a varchar(max) on SQL Server 2005 is not necessary since this is the default type created when specifying a :text field. As time goes on we will be testing other SQL Server specific data types are handled correctly when created in a migration.
60
+ Manually creating a varchar(max) is not necessary since this is the default type created when specifying a :text field. As time goes on we will be testing other SQL Server specific data types are handled correctly when created in a migration.
82
61
 
83
62
 
84
63
  ==== Native Text/String/Binary Data Type Accessor
85
64
 
86
- To pass the ActiveRecord tests we had to implement an class accessor for the native type created for :text columns. By default any :text column created by migrations will create these native types.
87
-
88
- * SQL Server 2000 is 'text'
89
- * SQL Server 2005 is 'varchar(max)'
90
-
91
- During testing this type is set to 'varchar(8000)' for SQL Server 2000. The reason is that rails expects to be able to use SQL = operators on text data types and this is not possible with a native 'text' data type in SQL Server. The default 'varchar(max)' for SQL Server 2005 can be queried using the SQL = operator and has plenty of storage space which is why we made it the default for 2005. If for some reason you want to change the data type created during migrations for any SQL Server version, you can configure this line to your liking in a config/initializers file.
65
+ To pass the ActiveRecord tests we had to implement an class accessor for the native type created for :text columns. By default any :text column created by migrations will create a 'varchar(max)' data type. This type can be queried using the SQL = operator and has plenty of storage space which is why we made it the default. If for some reason you want to change the data type created during migrations you can configure this line to your liking in a config/initializers file.
92
66
 
93
67
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'varchar(8000)'
94
-
95
- Also, there is a class attribute setter for the native string database type. This is the same for both SQL Server 2000 and 2005, 'varchar'. However in can be used instead of the #enable_default_unicode_types below for finer grain control over which types you want unicode safe when adding or changing the schema.
68
+
69
+ Also, there is a class attribute setter for the native string database type. This is the same for all SQL Server versions, 'varchar'. However it can be used instead of the #enable_default_unicode_types below for finer grain control over which types you want unicode safe when adding or changing the schema.
96
70
 
97
71
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'
98
72
 
99
- By default any :binary column created by migrations will create these native types
73
+ By default any :binary column created by migrations will create a 'varbinary(max)' data type. This too can be set using an initializer.
100
74
 
101
- * SQL Server 2000 is 'image'
102
- * SQL Server 2005 is 'varbinary(max)'
75
+ ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_binary_database_type = 'image'
103
76
 
104
77
 
105
78
  ==== Setting Unicode Types As Default
106
79
 
107
- By default the adapter will use non-unicode safe data types for :string and :text types when DEFINING or CHANGING the schema. If you choose, you can set the following class attribute in a config/initializers file that will change this behavior. When set to true it has the equivalent meaning as the two lower items. These examples show detail level alternatives to achieve similar effects.
80
+ By default the adapter will use non-unicode safe data types for :string and :text types when defining/changing the schema. If you choose, you can set the following class attribute in a config/initializers file that will change this behavior. When set to true it has the equivalent meaning as the two lower items. These examples show detail level alternatives to achieve similar effects.
108
81
 
109
82
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = true
110
83
 
111
- # SQL Server 2000
112
- ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'ntext'
113
- ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'
114
-
115
- # SQL Server 2005
116
84
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'nvarchar(max)'
117
85
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'
118
86
 
@@ -121,10 +89,11 @@ It is important to remember that unicode types in SQL Server have approximately
121
89
 
122
90
  ==== Schema Information Logging
123
91
 
124
- By default all queries to the INFORMATION_SCHEMA table is silenced. If you think logging these queries are useful, you can enable it by adding this like to a config/initializers file.
92
+ By default all queries to the INFORMATION_SCHEMA table is silenced. If you think logging these queries are useful, you can enable it by adding this like to a initializer file.
125
93
 
126
94
  ActiveRecord::ConnectionAdapters::SQLServerAdapter.log_info_schema_queries = true
127
95
 
96
+
128
97
  ==== Auto Connecting
129
98
 
130
99
  By default the adapter will auto connect to lost DB connections. For every query it will retry at intervals of 2, 4, 8, 16 and 32 seconds. During each retry it will callback out to ActiveRecord::Base.did_retry_sqlserver_connection(connection,count). When all retries fail, it will callback to ActiveRecord::Base.did_lose_sqlserver_connection(connection). Both implementations of these methods are to write to the rails logger, however, they make great override points for notifications like Hoptoad. If you want to disable automatic reconnections use the following in an initializer.
@@ -134,22 +103,23 @@ By default the adapter will auto connect to lost DB connections. For every query
134
103
 
135
104
  == Versions
136
105
 
137
- It is our goal to match the adapter version with each version of rails. However we will track our own tiny version independent of ActiveRecord. For example, an adapter version of 2.2.x will work on any 2.2.x version of ActiveRecord. This convention will be used in both the Git tags as well as the Rubygems versioning.
106
+ It is our goal to match the adapter version with each version of rails. However we will track our own tiny version independent of ActiveRecord. For example, an adapter version of 2.3.x will work on any 2.3.x version of ActiveRecord. Version 3.x will track ActiveRecord 3. This convention will be used in both the Git tags as well as the gems versioning.
138
107
 
139
108
 
140
109
  == Installation
141
110
 
142
- You will need Ruby ODBC. If you are using the adapter under 1.9, then you need at least ruby-odbc version 0.9996. ODBC is the preferred mode, however if you are using IronRuby you can use the ADONET connection mode which uses native System.Data connection. Other connection modes may be supported, possibly a straight FreeTDS layer. The sky is the limit now and we have a code that can be accept these optional transports. If you are interested in helping, open a ticket and submit a patch. Or start a conversation on the Google Group.
111
+ You will need Ruby ODBC. If you are using the adapter under 1.9, then you need at least ruby-odbc version 0.99992. ODBC is the preferred mode, however if you are using IronRuby you can use the ADONET connection mode which uses native System.Data connection. Other connection modes may be supported, possibly a straight FreeTDS layer. The sky is the limit for optional transports. If you are interested in helping, open a ticket and submit a patch. Or start a conversation on the Google Group.
143
112
 
144
113
  $ gem install activerecord-sqlserver-adapter
145
114
 
146
- Optionally configure your gem dependencies in your rails environment.rb file.
115
+ Optionally configure your gem dependencies in your Gemfile.
147
116
 
148
- config.gem 'activerecord-sqlserver-adapter', :version => 'x.x.xx'
117
+ gem 'activerecord-sqlserver-adapter', '3.x.xx'
149
118
 
150
- Here are some external links for libraries and/or tutorials on how to install any other additional components to use this adapter. If you know of a good one that we can include here, just let us know.
119
+ 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!
120
+
121
+ http://wiki.github.com/rails-sqlserver/activerecord-sqlserver-adapter/platform-installation
151
122
 
152
- * http://www.ch-werner.de/rubyodbc/
153
123
 
154
124
 
155
125
  == IronRuby ADONET Mode
@@ -165,28 +135,30 @@ Currently IronRuby is passing most of the ActiveRecord and Adapter tests. Here i
165
135
  http://gist.github.com/381101
166
136
 
167
137
 
138
+
168
139
  == Contributing
169
140
 
170
141
  If you’d 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 Google list, IRC, 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.
171
142
 
172
- * Github: http://github.com/rails-sqlserver
143
+ * Github: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
173
144
  * Google Group: http://groups.google.com/group/rails-sqlserver-adapter
174
145
  * IRC Room: #rails-sqlserver on irc.freenode.net
175
146
 
176
147
 
177
- == Credits
178
148
 
179
- Many many people have contributed. If you do not see your name here and it should be let us know.
149
+ == Credits & Contributions
150
+
151
+ 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.
180
152
 
181
153
  * Ken Collins
182
- * Erik Bryn
183
154
  * Murray Steele
184
155
  * Shawn Balestracci
185
156
  * Joe Rafaniello
186
157
  * Tom Ward
187
158
 
188
159
 
160
+
189
161
  == License
190
162
 
191
- Copyright © 2008. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
163
+ Copyright © 2008-2010. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
192
164
 
@@ -0,0 +1,57 @@
1
+ require 'active_record/version'
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module Sqlserver
6
+ module CoreExt
7
+ module ActiveRecord
8
+
9
+ def self.included(klass)
10
+ klass.extend ClassMethods
11
+ class << klass
12
+ alias_method_chain :reset_column_information, :sqlserver_cache_support
13
+ end
14
+ end
15
+
16
+ module ClassMethods
17
+
18
+ def execute_procedure(proc_name, *variables)
19
+ if connection.respond_to?(:execute_procedure)
20
+ connection.execute_procedure(proc_name,*variables)
21
+ else
22
+ []
23
+ end
24
+ end
25
+
26
+ def coerce_sqlserver_date(*attributes)
27
+ write_inheritable_attribute :coerced_sqlserver_date_columns, Set.new(attributes.map(&:to_s))
28
+ end
29
+
30
+ def coerce_sqlserver_time(*attributes)
31
+ write_inheritable_attribute :coerced_sqlserver_time_columns, Set.new(attributes.map(&:to_s))
32
+ end
33
+
34
+ def coerced_sqlserver_date_columns
35
+ read_inheritable_attribute(:coerced_sqlserver_date_columns) || []
36
+ end
37
+
38
+ def coerced_sqlserver_time_columns
39
+ read_inheritable_attribute(:coerced_sqlserver_time_columns) || []
40
+ end
41
+
42
+ def reset_column_information_with_sqlserver_cache_support
43
+ connection.send(:initialize_sqlserver_caches) if connection.respond_to?(:sqlserver?)
44
+ reset_column_information_without_sqlserver_cache_support
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+ ActiveRecord::Base.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ActiveRecord
57
+
@@ -0,0 +1,57 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module Sqlserver
4
+ module CoreExt
5
+ module ODBC
6
+
7
+ module TimeStamp
8
+
9
+ def to_sqlserver_string
10
+ date, time, nanoseconds = to_s.split(' ')
11
+ "#{date} #{time}.#{sprintf("%03d",nanoseconds.to_i/1000000)}"
12
+ end
13
+
14
+ end
15
+
16
+ module Statement
17
+
18
+ def finished?
19
+ begin
20
+ connected?
21
+ false
22
+ rescue *Database.parent_modules_error_exceptions
23
+ true
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ module Database
30
+
31
+ def self.parent_modules
32
+ @parent_module ||= ['ODBC','ODBC_UTF8','ODBC_NONE'].map{ |odbc_ns| odbc_ns.constantize rescue nil }.compact
33
+ end
34
+
35
+ def self.parent_modules_error_exceptions
36
+ @parent_modules_error_exceptions ||= parent_modules.map { |odbc_ns| "::#{odbc_ns}::Error".constantize }
37
+ end
38
+
39
+ def run_block(*args)
40
+ yield sth = run(*args)
41
+ sth.drop
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ ['ODBC','ODBC_UTF8','ODBC_NONE'].map{ |odbc_ns| odbc_ns.constantize rescue nil }.compact.each do |ns|
53
+ ns::TimeStamp.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ODBC::TimeStamp
54
+ ns::Statement.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ODBC::Statement
55
+ ns::Database.send :include, ActiveRecord::ConnectionAdapters::Sqlserver::CoreExt::ODBC::Database
56
+ end
57
+