activerecord-sqlserver-adapter 4.0.4 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a54d7e571a64b7870abe37edf41a68c27a64cb1
4
- data.tar.gz: 1d6c387c805cd8770d73f51aa64c011b28d51018
3
+ metadata.gz: 1769be5dc11de446932e700fa5d565eedd0acb13
4
+ data.tar.gz: a27fc285acdf1b2d18c464effb4251a6a657106d
5
5
  SHA512:
6
- metadata.gz: '0923cb551fe43f0af696f9cea6b638010c6b439de596e564c0cd45522b00b4214902b7d0b5f6e80b23c2a19f3e39517f0bc6db96e373edba3a435c8fa659d1de'
7
- data.tar.gz: 5fc8c2fba1b67b1bdc46ea7a42ed6d569bab69bc4c4daae2cba13a81b724aa9123615276f17d501a644ba7b95be1d1fe4aa61f2f63d6113b01c346e54fc6d94d
6
+ metadata.gz: bbb747777f956819b3c0f74e0c50d144462a11736416a66cc09d34214195583c6fb1e1d120599e6d5b7212238a7dc89d7c4f0fcaa456bae7e2b45d924fb90087
7
+ data.tar.gz: 2520b82a442e5dd2dceb78731a8689251bdcc50bc40c2d58b955330b39a16d98b64b08de54d10afc72292fa36a7ccc5a74092167a9f01fee82ab03b942c068da
data/CHANGELOG CHANGED
@@ -1,25 +1,4 @@
1
- * 4.0.4 *
2
-
3
- * Add `WITH NO_INFOMSGS` to `user_options` method. Fixes #580
4
-
5
-
6
- * 4.0.3 *
7
-
8
- * Fix parens around `enable_default_unicode_types`. Fixes #562
9
-
10
-
11
- * 4.0.2 *
12
-
13
- * Added vNext support.
14
-
15
-
16
- * 4.0.1 *
17
-
18
- * Added 2014 and 2016 to supported list.
19
-
20
-
21
1
  * 4.0.0 *
22
-
23
2
  * Dropped support for ruby 1.8.7
24
3
  * Removed deadlock victim retry in favor of Isolation Level
25
4
  * Removed auto_explain_threshold_in_seconds (not used in rails 4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.4
1
+ 4.1.0
@@ -18,8 +18,8 @@ module ActiveRecord
18
18
  if id_insert_table_name = sqlserver_options[:insert] ? query_requires_identity_insert?(sql) : nil
19
19
  with_identity_insert_enabled(id_insert_table_name) { do_exec_query(sql, name, binds) }
20
20
  elsif update_sql?(sql)
21
- sql = strip_ident_from_update(sql)
22
- do_exec_query(sql, name, binds)
21
+ sql = strip_ident_from_update(sql)
22
+ do_exec_query(sql, name, binds)
23
23
  else
24
24
  do_exec_query(sql, name, binds)
25
25
  end
@@ -56,15 +56,15 @@ module ActiveRecord
56
56
  do_execute 'IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION'
57
57
  end
58
58
 
59
- def create_savepoint
60
- disable_auto_reconnect { do_execute "SAVE TRANSACTION #{current_savepoint_name}" }
59
+ def create_savepoint(name = current_savepoint_name)
60
+ disable_auto_reconnect { do_execute "SAVE TRANSACTION #{name}" }
61
61
  end
62
62
 
63
- def release_savepoint
63
+ def release_savepoint(name = current_savepoint_name)
64
64
  end
65
65
 
66
- def rollback_to_savepoint
67
- disable_auto_reconnect { do_execute "ROLLBACK TRANSACTION #{current_savepoint_name}" }
66
+ def rollback_to_savepoint(name = current_savepoint_name)
67
+ disable_auto_reconnect { do_execute "ROLLBACK TRANSACTION #{name}" }
68
68
  end
69
69
 
70
70
  def add_limit_offset!(_sql, _options)
@@ -122,7 +122,7 @@ module ActiveRecord
122
122
 
123
123
  def user_options
124
124
  return {} if sqlserver_azure?
125
- select_rows('DBCC USEROPTIONS WITH NO_INFOMSGS', 'SCHEMA').reduce(HashWithIndifferentAccess.new) do |values, row|
125
+ select_rows('dbcc useroptions', 'SCHEMA').reduce(HashWithIndifferentAccess.new) do |values, row|
126
126
  if row.instance_of? Hash
127
127
  set_option = row.values[0].gsub(/\s+/, '_')
128
128
  user_value = row.values[1]
@@ -334,7 +334,11 @@ module ActiveRecord
334
334
  next if ar_column && column.sql_type == 'timestamp'
335
335
  v = value
336
336
  names_and_types << if ar_column
337
- v = value.to_i if column.is_integer? && value.present?
337
+ if column.is_integer? && value.present?
338
+ v = value.to_i
339
+ # Reset the casted value to the bind as required by Rails 4.1
340
+ binds[index] = [column, v]
341
+ end
338
342
  "@#{index} #{column.sql_type_for_statement}"
339
343
  elsif column.acts_like?(:string)
340
344
  "@#{index} nvarchar(max)"
@@ -67,7 +67,7 @@ module ActiveRecord
67
67
  if column.respond_to?(:sql_type) && column.sql_type == 'timestamp'
68
68
  nil
69
69
  else
70
- Arel.sql "@#{index}"
70
+ Arel::Nodes::BindParam.new "@#{index}"
71
71
  end
72
72
  end
73
73
 
@@ -22,6 +22,34 @@ module ActiveRecord
22
22
  super
23
23
  end
24
24
  end
25
+
26
+ def visit_TableDefinition(o)
27
+ quoted_name = "#{quote_table_name((o.temporary ? '#' : '') + o.name.to_s)} "
28
+
29
+ if o.as
30
+ if o.as.is_a?(ActiveRecord::Relation)
31
+ select = o.as.to_sql
32
+ elsif o.as.is_a?(String)
33
+ select = o.as
34
+ else
35
+ raise 'Only able to generate a table from a SELECT statement passed as a String or ActiveRecord::Relation'
36
+ end
37
+
38
+ create_sql = 'SELECT * INTO '
39
+ create_sql << quoted_name
40
+ create_sql << 'FROM ('
41
+ create_sql << select
42
+ create_sql << ') AS __sq'
43
+
44
+ else
45
+ create_sql = "CREATE TABLE "
46
+ create_sql << quoted_name
47
+ create_sql << "(#{o.columns.map { |c| accept c }.join(', ')}) "
48
+ create_sql << "#{o.options}"
49
+ end
50
+
51
+ create_sql
52
+ end
25
53
  end
26
54
  end
27
55
  end
@@ -16,6 +16,12 @@ module ActiveRecord
16
16
  super || tables.include?(unquoted_table_name) || views.include?(unquoted_table_name)
17
17
  end
18
18
 
19
+ def create_table(table_name, options = {})
20
+ res = super
21
+ schema_cache.clear_table_cache!(table_name)
22
+ res
23
+ end
24
+
19
25
  def indexes(table_name, name = nil)
20
26
  data = select("EXEC sp_helpindex #{quote(table_name)}", name) rescue []
21
27
  data.reduce([]) do |indexes, index|
@@ -256,7 +262,7 @@ module ActiveRecord
256
262
  nil
257
263
  else
258
264
  match_data = ci[:default_value].match(/\A\(+N?'?(.*?)'?\)+\Z/m)
259
- match_data ? match_data[1] : nil
265
+ match_data ? match_data[1].gsub("''", "'") : nil
260
266
  end
261
267
  ci[:null] = ci[:is_nullable].to_i == 1
262
268
  ci.delete(:is_nullable)
@@ -408,8 +414,8 @@ module ActiveRecord
408
414
 
409
415
  private
410
416
 
411
- def create_table_definition(name, temporary, options)
412
- TableDefinition.new native_database_types, name, temporary, options
417
+ def create_table_definition(name, temporary, options, as = nil)
418
+ TableDefinition.new native_database_types, name, temporary, options, as
413
419
  end
414
420
  end
415
421
  end
@@ -37,7 +37,7 @@ module ActiveRecord
37
37
  VERSION = File.read(File.expand_path('../../../../VERSION', __FILE__)).strip
38
38
  ADAPTER_NAME = 'SQLServer'.freeze
39
39
  DATABASE_VERSION_REGEXP = /Microsoft SQL Server\s+"?(\d{4}|\w+)"?/
40
- SUPPORTED_VERSIONS = [2005, 2008, 2010, 2011, 2012, 2014, 2016]
40
+ SUPPORTED_VERSIONS = [2005, 2008, 2010, 2011, 2012]
41
41
 
42
42
  attr_reader :database_version, :database_year, :spid, :product_level, :product_version, :edition
43
43
 
@@ -65,9 +65,7 @@ module ActiveRecord
65
65
  if @database_version =~ /Azure/i
66
66
  @sqlserver_azure = true
67
67
  @database_version.match(/\s-\s([0-9.]+)/)[1]
68
- year = 2016
69
- elsif @database_version =~ /vNext/i
70
- year = 2016
68
+ year = 2012
71
69
  else
72
70
  year = DATABASE_VERSION_REGEXP.match(@database_version)[1]
73
71
  year == 'Denali' ? 2011 : year.to_i
@@ -231,7 +229,7 @@ module ActiveRecord
231
229
  end
232
230
 
233
231
  def native_text_database_type
234
- @@native_text_database_type || (enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)')
232
+ @@native_text_database_type || enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)'
235
233
  end
236
234
 
237
235
  def native_time_database_type
@@ -300,26 +298,26 @@ module ActiveRecord
300
298
  encoding: encoding(config),
301
299
  azure: config[:azure]
302
300
  ).tap do |client|
303
- if config[:azure]
304
- client.execute('SET ANSI_NULLS ON').do
305
- client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do
306
- client.execute('SET ANSI_NULL_DFLT_ON ON').do
307
- client.execute('SET IMPLICIT_TRANSACTIONS OFF').do
308
- client.execute('SET ANSI_PADDING ON').do
309
- client.execute('SET QUOTED_IDENTIFIER ON')
310
- client.execute('SET ANSI_WARNINGS ON').do
311
- else
312
- client.execute('SET ANSI_DEFAULTS ON').do
313
- client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do
314
- client.execute('SET IMPLICIT_TRANSACTIONS OFF').do
315
- end
301
+ if config[:azure]
302
+ client.execute('SET ANSI_NULLS ON').do
303
+ client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do
304
+ client.execute('SET ANSI_NULL_DFLT_ON ON').do
305
+ client.execute('SET IMPLICIT_TRANSACTIONS OFF').do
306
+ client.execute('SET ANSI_PADDING ON').do
307
+ client.execute('SET QUOTED_IDENTIFIER ON')
308
+ client.execute('SET ANSI_WARNINGS ON').do
309
+ else
310
+ client.execute('SET ANSI_DEFAULTS ON').do
311
+ client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do
312
+ client.execute('SET IMPLICIT_TRANSACTIONS OFF').do
313
+ end
316
314
  client.execute('SET TEXTSIZE 2147483647').do
317
315
  client.execute('SET CONCAT_NULL_YIELDS_NULL ON').do
318
316
  end
319
317
  end
320
318
 
321
319
  def appname(config)
322
- config[:appname] || configure_application_name || Rails.application.class.name.split('::').first rescue nil
320
+ config[:appname] || configure_application_name || Rails.application.class.name.split('::').first rescue nil
323
321
  end
324
322
 
325
323
  def login_timeout(config)
@@ -112,5 +112,5 @@ module ActiveRecord
112
112
  end
113
113
  end
114
114
  end # class SQLServerColumn
115
- end # module ConnectionAdapters
115
+ end # module ConnectionAdapters
116
116
  end # module ActiveRecord
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-sqlserver-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.4
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
8
8
  - Anna Carey
9
+ - Will Bond
9
10
  - Murray Steele
10
11
  - Shawn Balestracci
11
12
  - Joe Rafaniello
@@ -13,7 +14,7 @@ authors:
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
- date: 2017-03-26 00:00:00.000000000 Z
17
+ date: 2014-05-23 00:00:00.000000000 Z
17
18
  dependencies:
18
19
  - !ruby/object:Gem::Dependency
19
20
  name: activerecord
@@ -21,28 +22,28 @@ dependencies:
21
22
  requirements:
22
23
  - - "~>"
23
24
  - !ruby/object:Gem::Version
24
- version: 4.0.0
25
+ version: 4.1.0
25
26
  type: :runtime
26
27
  prerelease: false
27
28
  version_requirements: !ruby/object:Gem::Requirement
28
29
  requirements:
29
30
  - - "~>"
30
31
  - !ruby/object:Gem::Version
31
- version: 4.0.0
32
+ version: 4.1.0
32
33
  - !ruby/object:Gem::Dependency
33
34
  name: arel
34
35
  requirement: !ruby/object:Gem::Requirement
35
36
  requirements:
36
- - - "~>"
37
+ - - ">="
37
38
  - !ruby/object:Gem::Version
38
- version: 4.0.1
39
+ version: '0'
39
40
  type: :runtime
40
41
  prerelease: false
41
42
  version_requirements: !ruby/object:Gem::Requirement
42
43
  requirements:
43
- - - "~>"
44
+ - - ">="
44
45
  - !ruby/object:Gem::Version
45
- version: 4.0.1
46
+ version: '0'
46
47
  description: ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher.
47
48
  email: ken@metaskills.net
48
49
  executables: []
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project: activerecord-sqlserver-adapter
100
- rubygems_version: 2.6.8
101
+ rubygems_version: 2.2.2
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher.