activerecord-sqlserver-adapter 3.0.10 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ * 3.0.11 *
3
+
4
+ * Azure compatibility.
5
+
6
+ * TinyTDS enhancements for lost connections. Default connection mode.
7
+
8
+
2
9
  * 3.0.10 *
3
10
 
4
11
  * Fix #rowtable_orders visitor helper to use first column if no pk column was found.
@@ -104,6 +104,7 @@ module ActiveRecord
104
104
  end
105
105
 
106
106
  def use_database(database=nil)
107
+ return if sqlserver_azure?
107
108
  database ||= @connection_options[:database]
108
109
  do_execute "USE #{quote_table_name(database)}" unless database.blank?
109
110
  end
@@ -106,7 +106,7 @@ module ActiveRecord
106
106
  end
107
107
 
108
108
  def remove_index!(table_name, index_name)
109
- do_execute "DROP INDEX #{quote_table_name(table_name)}.#{quote_column_name(index_name)}"
109
+ do_execute "DROP INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}"
110
110
  end
111
111
 
112
112
  def type_to_sql(type, limit = nil, precision = nil, scale = nil)
@@ -18,12 +18,13 @@ module ActiveRecord
18
18
 
19
19
  def self.sqlserver_connection(config) #:nodoc:
20
20
  config = config.dup.symbolize_keys!
21
- config.reverse_merge! :mode => :odbc, :host => 'localhost', :username => 'sa', :password => ''
21
+ config.reverse_merge! :mode => :dblib, :host => 'localhost', :username => 'sa', :password => ''
22
22
  mode = config[:mode].to_s.downcase.underscore.to_sym
23
23
  case mode
24
24
  when :dblib
25
25
  raise ArgumentError, 'Missing :dataserver configuration.' unless config.has_key?(:dataserver)
26
26
  require_library_or_gem 'tiny_tds'
27
+ warn("TinyTds v0.4.3 or higher required. Using #{TinyTds::VERSION}") unless TinyTds::Client.instance_methods.include?("active?")
27
28
  when :odbc
28
29
  raise ArgumentError, 'Missing :dsn configuration.' unless config.has_key?(:dsn)
29
30
  if RUBY_VERSION < '1.9'
@@ -164,9 +165,9 @@ module ActiveRecord
164
165
  include Sqlserver::Errors
165
166
 
166
167
  ADAPTER_NAME = 'SQLServer'.freeze
167
- VERSION = '3.0.10'.freeze
168
+ VERSION = '3.0.11'.freeze
168
169
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
169
- SUPPORTED_VERSIONS = [2005,2008,2011].freeze
170
+ SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze
170
171
 
171
172
  attr_reader :database_version, :database_year,
172
173
  :connection_supports_native_types
@@ -181,8 +182,13 @@ module ActiveRecord
181
182
  super(@connection, logger)
182
183
  @database_version = info_schema_query { select_value('SELECT @@version') }
183
184
  @database_year = begin
184
- year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
185
- year == "Denali" ? 2011 : year.to_i
185
+ if @database_version =~ /Microsoft SQL Azure/i
186
+ @sqlserver_azure = true
187
+ @database_version.match(/\s(\d{4})\s/)[1].to_i
188
+ else
189
+ year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
190
+ year == "Denali" ? 2011 : year.to_i
191
+ end
186
192
  rescue
187
193
  0
188
194
  end
@@ -229,15 +235,10 @@ module ActiveRecord
229
235
  # === Abstract Adapter (Connection Management) ================== #
230
236
 
231
237
  def active?
232
- connected = case @connection_options[:mode]
233
- when :dblib
234
- !@connection.closed?
235
- when :odbc
236
- true
237
- else :adonet
238
- true
239
- end
240
- return false if !connected
238
+ case @connection_options[:mode]
239
+ when :dblib
240
+ return @connection.active?
241
+ end
241
242
  raw_connection_do("SELECT 1")
242
243
  true
243
244
  rescue *lost_connection_exceptions
@@ -294,6 +295,10 @@ module ActiveRecord
294
295
  @database_year == 2011
295
296
  end
296
297
 
298
+ def sqlserver_azure?
299
+ @sqlserver_azure && @database_year == 2010
300
+ end
301
+
297
302
  def version
298
303
  self.class::VERSION
299
304
  end
@@ -315,11 +320,11 @@ module ActiveRecord
315
320
  end
316
321
 
317
322
  def native_time_database_type
318
- sqlserver_2008? ? 'time' : 'datetime'
323
+ sqlserver_2005? ? 'datetime' : 'time'
319
324
  end
320
325
 
321
326
  def native_date_database_type
322
- sqlserver_2008? ? 'date' : 'datetime'
327
+ sqlserver_2005? ? 'datetime' : 'date'
323
328
  end
324
329
 
325
330
  def native_binary_database_type
@@ -366,11 +371,22 @@ module ActiveRecord
366
371
  :appname => appname,
367
372
  :login_timeout => login_timeout,
368
373
  :timeout => timeout,
369
- :encoding => encoding
374
+ :encoding => encoding,
375
+ :azure => config[:azure]
370
376
  }).tap do |client|
371
- client.execute("SET ANSI_DEFAULTS ON").do
372
- client.execute("SET IMPLICIT_TRANSACTIONS OFF").do
373
- client.execute("SET CURSOR_CLOSE_ON_COMMIT OFF").do
377
+ if config[:azure]
378
+ client.execute("SET ANSI_NULLS ON").do
379
+ client.execute("SET CURSOR_CLOSE_ON_COMMIT OFF").do
380
+ client.execute("SET ANSI_NULL_DFLT_ON ON").do
381
+ client.execute("SET IMPLICIT_TRANSACTIONS OFF").do
382
+ client.execute("SET ANSI_PADDING ON").do
383
+ client.execute("SET QUOTED_IDENTIFIER ON")
384
+ client.execute("SET ANSI_WARNINGS ON").do
385
+ else
386
+ client.execute("SET ANSI_DEFAULTS ON").do
387
+ client.execute("SET CURSOR_CLOSE_ON_COMMIT OFF").do
388
+ client.execute("SET IMPLICIT_TRANSACTIONS OFF").do
389
+ end
374
390
  end
375
391
  when :odbc
376
392
  odbc = ['::ODBC','::ODBC_UTF8','::ODBC_NONE'].detect{ |odbc_ns| odbc_ns.constantize rescue nil }.constantize
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 10
10
- version: 3.0.10
9
+ - 11
10
+ version: 3.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Collins
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2011-03-01 00:00:00 -05:00
22
+ date: 2011-04-01 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements: []
109
109
 
110
110
  rubyforge_project: activerecord-sqlserver-adapter
111
- rubygems_version: 1.5.0
111
+ rubygems_version: 1.6.2
112
112
  signing_key:
113
113
  specification_version: 3
114
114
  summary: SQL Server 2005 and 2008 Adapter For ActiveRecord.