activerecord-sqlserver-adapter 3.1.0.rc5 → 3.1.0.rc6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  * 3.1.0 *
3
3
 
4
+ * Make auto reconnect duration configurable. Fixes #109 [David Chelimsky]
5
+
4
6
  * Quote most time objects to use ISO8601 format to be multi-language dateformat compatible. The [datetime] data type is
5
7
  automatically limited to milliseconds while [time] & [datetimeoffset] have full support. Even included a Date/Time
6
8
  ActiveSupport formatter that is used per the language settings of the connection.
@@ -38,7 +38,7 @@ module ActiveRecord
38
38
 
39
39
  def quote_column_name(name)
40
40
  @sqlserver_quoted_column_and_table_names[name] ||=
41
- name.to_s.split('.').map{ |n| n =~ /^\[.*\]$/ ? n : "[#{n}]" }.join('.')
41
+ name.to_s.split('.').map{ |n| n =~ /^\[.*\]$/ ? n : "[#{n.to_s.gsub(']', ']]')}]" }.join('.')
42
42
  end
43
43
 
44
44
  def quote_table_name(name)
@@ -159,7 +159,7 @@ module ActiveRecord
159
159
  include Sqlserver::Errors
160
160
 
161
161
  ADAPTER_NAME = 'SQLServer'.freeze
162
- VERSION = '3.1.0.rc5'.freeze
162
+ VERSION = '3.1.0.rc6'.freeze
163
163
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
164
164
  SUPPORTED_VERSIONS = [2005,2008,2010,2011].freeze
165
165
 
@@ -167,10 +167,17 @@ module ActiveRecord
167
167
 
168
168
  cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
169
169
  :log_info_schema_queries, :enable_default_unicode_types, :auto_connect,
170
- :cs_equality_operator, :lowercase_schema_reflection
170
+ :cs_equality_operator, :lowercase_schema_reflection, :auto_connect_duration
171
171
 
172
172
  self.enable_default_unicode_types = true
173
173
 
174
+ class << self
175
+
176
+ def visitor_for(pool)
177
+ Arel::Visitors::SQLServer.new(pool)
178
+ end
179
+
180
+ end
174
181
 
175
182
  def initialize(logger,config)
176
183
  @connection_options = config
@@ -310,6 +317,10 @@ module ActiveRecord
310
317
  @@auto_connect.is_a?(FalseClass) ? false : true
311
318
  end
312
319
 
320
+ def auto_connect_duration
321
+ @@auto_connect_duration ||= 10
322
+ end
323
+
313
324
  def native_string_database_type
314
325
  @@native_string_database_type || (enable_default_unicode_types ? 'nvarchar' : 'varchar')
315
326
  end
@@ -443,7 +454,7 @@ module ActiveRecord
443
454
  return false unless auto_connect
444
455
  @auto_connecting = true
445
456
  count = 0
446
- while count <= 5
457
+ while count <= (auto_connect_duration / 2)
447
458
  sleep 2** count
448
459
  ActiveRecord::Base.did_retry_sqlserver_connection(self,count)
449
460
  return true if reconnect!
@@ -21,14 +21,16 @@ module Arel
21
21
  end
22
22
 
23
23
  class SelectManager < Arel::TreeManager
24
-
24
+
25
+ AR_CA_SQLSA_NAME = 'ActiveRecord::ConnectionAdapters::SQLServerAdapter'.freeze
26
+
25
27
  # Getting real Ordering objects is very important for us. We need to be able to call #uniq on
26
28
  # a colleciton of them reliably as well as using their true object attributes to mutate them
27
29
  # to grouping objects for the inner sql during a select statment with an offset/rownumber. So this
28
30
  # is here till ActiveRecord & ARel does this for us instead of using SqlLiteral objects.
29
31
  alias :order_without_sqlserver :order
30
32
  def order(*expr)
31
- return order_without_sqlserver(*expr) unless Arel::Visitors::SQLServer === @visitor
33
+ return order_without_sqlserver(*expr) unless engine_activerecord_sqlserver_adapter?
32
34
  @ast.orders.concat(expr.map{ |x|
33
35
  case x
34
36
  when Arel::Attributes::Attribute
@@ -55,7 +57,7 @@ module Arel
55
57
  # custom string hints down. See the visit_Arel_Nodes_LockWithSQLServer delegation method.
56
58
  alias :lock_without_sqlserver :lock
57
59
  def lock(locking=true)
58
- if Arel::Visitors::SQLServer === @visitor
60
+ if engine_activerecord_sqlserver_adapter?
59
61
  case locking
60
62
  when true
61
63
  locking = Arel.sql('WITH(HOLDLOCK, ROWLOCK)')
@@ -69,7 +71,13 @@ module Arel
69
71
  lock_without_sqlserver(locking)
70
72
  end
71
73
  end
72
-
74
+
75
+ private
76
+
77
+ def engine_activerecord_sqlserver_adapter?
78
+ @engine.connection && @engine.connection.class.name == AR_CA_SQLSA_NAME
79
+ end
80
+
73
81
  end
74
82
 
75
83
  module Visitors
@@ -117,7 +125,7 @@ module Arel
117
125
  end
118
126
 
119
127
  def visit_Arel_Nodes_Bin(o)
120
- "#{visit o.expr} #{@engine.connection.cs_equality_operator}"
128
+ "#{visit o.expr} #{@connection.cs_equality_operator}"
121
129
  end
122
130
 
123
131
  # SQLServer ToSql/Visitor (Additions)
@@ -189,7 +197,7 @@ module Arel
189
197
 
190
198
  def source_with_lock_for_select_statement(o)
191
199
  core = o.cores.first
192
- source = visit(core.source).strip if core.source
200
+ source = "FROM #{visit(core.source).strip}" if core.source
193
201
  if source && o.lock
194
202
  lock = visit o.lock
195
203
  index = source.match(/FROM [\w\[\]\.]+/)[0].length
@@ -272,6 +280,14 @@ module Arel
272
280
  o.limit &&
273
281
  !join_in_select_statement?(o)
274
282
  end
283
+
284
+ def select_primary_key_sql?(o)
285
+ core = o.cores.first
286
+ return false if core.projections.size != 1
287
+ p = core.projections.first
288
+ t = table_from_select_statement(o)
289
+ Arel::Attributes::Attribute === p && t.primary_key && t.primary_key.name == p.name
290
+ end
275
291
 
276
292
  def find_and_fix_uncorrelated_joins_in_select_statement(o)
277
293
  core = o.cores.first
@@ -315,6 +331,8 @@ module Arel
315
331
  end
316
332
  elsif function_select_statement?(o)
317
333
  [Arel.star]
334
+ elsif select_primary_key_sql?(o)
335
+ [Arel.sql("[__rnt].#{quote_column_name(core.projections.first.name)}")]
318
336
  else
319
337
  core.projections.map do |x|
320
338
  if x.respond_to?(:relation)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424111
4
+ hash: 15424105
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
10
  - rc
11
- - 5
12
- version: 3.1.0.rc5
11
+ - 6
12
+ version: 3.1.0.rc6
13
13
  platform: ruby
14
14
  authors:
15
15
  - Ken Collins
@@ -21,7 +21,7 @@ autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
23
 
24
- date: 2011-07-26 00:00:00 -04:00
24
+ date: 2011-08-17 00:00:00 -04:00
25
25
  default_executable:
26
26
  dependencies:
27
27
  - !ruby/object:Gem::Dependency
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- hash: 15424111
35
+ hash: 15424105
36
36
  segments:
37
37
  - 3
38
38
  - 1
39
39
  - 0
40
40
  - rc
41
- - 5
42
- version: 3.1.0.rc5
41
+ - 6
42
+ version: 3.1.0.rc6
43
43
  type: :runtime
44
44
  version_requirements: *id001
45
45
  description: SQL Server 2005 and 2008 Adapter For ActiveRecord