GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
merge sybase changes to 1.2

git-svn-id: 
http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5840 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
NZKoz (author)
Thu Jan 04 16:16:54 -0800 2007
commit  1872150b1d1807b1c4172fb486cfb5c1819847fe
tree    7262142f87d03660a71f1153ccf516355bf3ecf8
parent  e9a7b233f6b44abd9e50fb6e734f897ba9b3333a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *1.15.0 RC2*
0
 
0
+* Bring the sybase adapter up to scratch for 1.2 release. [jsheets]
0
+
0
 * Oracle: fix connection reset failure. #6846 [leonlleslie]
0
 
0
 * Subclass instantiation doesn't try to explicitly require the corresponding subclass. #6840 [leei, Jeremy Kemper]
...
1
2
 
 
 
 
3
4
5
 
6
7
8
9
10
 
 
 
 
 
 
 
11
12
13
...
77
78
79
80
 
81
82
83
...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
148
149
150
 
 
 
 
 
 
 
 
 
151
152
153
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
212
213
214
215
216
217
218
219
220
221
222
223
224
 
225
226
227
228
229
230
 
 
 
231
232
233
234
235
236
237
238
239
240
241
 
242
243
244
245
246
 
247
248
249
250
251
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
254
255
256
257
...
302
303
304
305
 
306
307
308
...
318
319
320
 
 
 
 
 
321
322
323
...
334
335
336
337
 
338
 
339
340
341
 
342
343
 
344
345
346
...
350
351
352
353
354
 
 
355
356
 
357
358
359
...
418
419
420
421
422
423
424
425
426
427
428
 
 
 
 
 
 
429
430
431
432
433
434
435
436
437
 
438
439
440
441
442
443
444
 
 
 
 
445
446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
448
 
449
450
451
...
456
457
458
 
 
459
460
461
462
463
464
465
466
467
468
469
470
 
 
 
 
 
 
 
471
472
473
 
474
475
 
476
477
478
...
490
491
492
493
494
495
496
 
 
 
 
 
497
498
 
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
 
 
 
551
552
 
553
554
 
555
556
557
558
559
560
561
562
563
564
565
 
 
 
 
 
 
 
 
566
567
568
...
654
655
656
657
658
659
660
 
 
 
 
 
 
 
 
661
662
663
...
1
 
2
3
4
5
6
 
7
8
9
10
 
 
 
11
12
13
14
15
16
17
18
19
20
...
84
85
86
 
87
88
89
90
...
105
106
107
 
 
 
 
 
 
 
 
 
 
108
109
110
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
176
177
178
 
 
 
 
 
 
 
 
179
180
181
...
210
211
212
 
 
 
 
 
 
 
 
 
 
213
214
215
216
 
 
 
217
218
219
220
221
222
223
224
225
 
 
 
 
 
226
227
228
229
 
 
230
231
232
233
234
 
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
 
269
270
271
...
316
317
318
 
319
320
321
322
...
332
333
334
335
336
337
338
339
340
341
342
...
353
354
355
 
356
357
358
359
360
 
361
362
 
363
364
365
366
...
370
371
372
 
 
373
374
375
 
376
377
378
379
...
438
439
440
 
 
 
 
 
 
 
 
441
442
443
444
445
446
447
448
449
450
451
452
 
 
 
453
454
 
 
 
 
 
 
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
...
486
487
488
489
490
491
 
 
 
 
 
 
 
 
 
 
 
492
493
494
495
496
497
498
499
500
 
501
502
 
503
504
505
506
...
518
519
520
 
 
 
 
521
522
523
524
525
526
 
527
528
529
530
531
532
533
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
535
536
537
538
539
 
 
540
541
542
543
 
544
545
 
546
547
 
 
 
 
 
 
 
 
548
 
549
550
551
552
553
554
555
556
557
558
559
...
645
646
647
 
 
 
 
648
649
650
651
652
653
654
655
656
657
658
0
@@ -1,13 +1,20 @@
0
 # sybase_adaptor.rb
0
-# Author: John Sheets <dev@metacasa.net>
0
+# Author: John R. Sheets
0
+#
0
+# 01 Mar 2006: Initial version. Based on code from Will Sobel
0
+# (http://dev.rubyonrails.org/ticket/2030)
0
 #
0
-# 01 Mar 2006: Initial version.
0
 # 17 Mar 2006: Added support for migrations; fixed issues with :boolean columns.
0
+#
0
 # 13 Apr 2006: Improved column type support to properly handle dates and user-defined
0
 # types; fixed quoting of integer columns.
0
-#
0
-# Based on code from Will Sobel (http://dev.rubyonrails.org/ticket/2030)
0
-#
0
+#
0
+# 05 Jan 2007: Updated for Rails 1.2 release:
0
+# restricted Fixtures#insert_fixtures monkeypatch to Sybase adapter;
0
+# removed SQL type precision from TEXT type to fix broken
0
+# ActiveRecordStore (jburks, #6878); refactored select() to use execute();
0
+# fixed leaked exception for no-op change_column(); removed verbose SQL dump
0
+# from columns(); added missing scale parameter in normalize_type().
0
 
0
 require 'active_record/connection_adapters/abstract_adapter'
0
 
0
@@ -77,7 +84,7 @@ module ActiveRecord
0
     # 2> go
0
     class SybaseAdapter < AbstractAdapter # :nodoc:
0
       class ColumnWithIdentity < Column
0
- attr_reader :identity, :primary
0
+ attr_reader :identity
0
 
0
         def initialize(name, default, sql_type = nil, nullable = nil, identity = nil, primary = nil)
0
           super(name, default, sql_type, nullable)
0
@@ -98,16 +105,6 @@ module ActiveRecord
0
           end
0
         end
0
 
0
- def self.string_to_time(string)
0
- return string unless string.is_a?(String)
0
-
0
- # Since Sybase doesn't handle DATE or TIME, handle it here.
0
- # Populate nil year/month/day with string_to_dummy_time() values.
0
- time_array = ParseDate.parsedate(string)[0..5]
0
- time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
0
- Time.send(Base.default_timezone, *time_array) rescue nil
0
- end
0
-
0
         def self.string_to_binary(value)
0
           "0x#{value.unpack("H*")[0]}"
0
         end
0
@@ -148,6 +145,15 @@ module ActiveRecord
0
         }
0
       end
0
 
0
+ def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
0
+ return super unless type.to_s == 'integer'
0
+ if !limit.nil? && limit < 4
0
+ 'smallint'
0
+ else
0
+ 'integer'
0
+ end
0
+ end
0
+
0
       def adapter_name
0
         'Sybase'
0
       end
0
@@ -170,14 +176,6 @@ module ActiveRecord
0
         30
0
       end
0
 
0
- def columns(table_name, name = nil)
0
- table_structure(table_name).inject([]) do |columns, column|
0
- name, default, type, nullable, identity, primary = column
0
- columns << ColumnWithIdentity.new(name, default, type, nullable, identity, primary)
0
- columns
0
- end
0
- end
0
-
0
       def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
0
         begin
0
           table_name = get_table_name(sql)
0
@@ -212,46 +210,62 @@ module ActiveRecord
0
       end
0
 
0
       def execute(sql, name = nil)
0
- log(sql, name) do
0
- @connection.context.reset
0
- @connection.set_rowcount(@limit || 0)
0
- @limit = @offset = nil
0
- @connection.sql_norow(sql)
0
- if @connection.cmd_fail? or @connection.context.failed?
0
- raise "SQL Command Failed for #{name}: #{sql}\nMessage: #{@connection.context.message}"
0
- end
0
- end
0
- # Return rows affected
0
+ raw_execute(sql, name)
0
         @connection.results[0].row_count
0
       end
0
 
0
- def begin_db_transaction() execute "BEGIN TRAN" end
0
- def commit_db_transaction() execute "COMMIT TRAN" end
0
- def rollback_db_transaction() execute "ROLLBACK TRAN" end
0
+ def begin_db_transaction() raw_execute "BEGIN TRAN" end
0
+ def commit_db_transaction() raw_execute "COMMIT TRAN" end
0
+ def rollback_db_transaction() raw_execute "ROLLBACK TRAN" end
0
 
0
       def current_database
0
         select_one("select DB_NAME() as name")["name"]
0
       end
0
 
0
       def tables(name = nil)
0
- tables = []
0
- select("select name from sysobjects where type='U'", name).each do |row|
0
- tables << row['name']
0
- end
0
- tables
0
+ select("select name from sysobjects where type='U'", name).map { |row| row['name'] }
0
       end
0
 
0
       def indexes(table_name, name = nil)
0
- indexes = []
0
- select("exec sp_helpindex #{table_name}", name).each do |index|
0
+ select("exec sp_helpindex #{table_name}", name).map do |index|
0
           unique = index["index_description"] =~ /unique/
0
           primary = index["index_description"] =~ /^clustered/
0
           if !primary
0
             cols = index["index_keys"].split(", ").each { |col| col.strip! }
0
- indexes << IndexDefinition.new(table_name, index["index_name"], unique, cols)
0
+ IndexDefinition.new(table_name, index["index_name"], unique, cols)
0
           end
0
+ end.compact
0
+ end
0
+
0
+ def columns(table_name, name = nil)
0
+ sql = <<SQLTEXT
0
+SELECT col.name AS name, type.name AS type, col.prec, col.scale,
0
+ col.length, col.status, obj.sysstat2, def.text
0
+ FROM sysobjects obj, syscolumns col, systypes type, syscomments def
0
+ WHERE obj.id = col.id AND col.usertype = type.usertype AND col.cdefault *= def.id
0
+ AND obj.type = 'U' AND obj.name = '#{table_name}' ORDER BY col.colid
0
+SQLTEXT
0
+ @logger.debug "Get Column Info for table '#{table_name}'" if @logger
0
+ @connection.set_rowcount(0)
0
+ @connection.sql(sql)
0
+
0
+ raise "SQL Command for table_structure for #{table_name} failed\nMessage: #{@connection.context.message}" if @connection.context.failed?
0
+ return nil if @connection.cmd_fail?
0
+
0
+ @connection.top_row_result.rows.map do |row|
0
+ name, type, prec, scale, length, status, sysstat2, default = row
0
+ name.sub!(/_$/o, '')
0
+ type = normalize_type(type, prec, scale, length)
0
+ default_value = nil
0
+ if default =~ /DEFAULT\s+(.+)/o
0
+ default_value = $1.strip
0
+ default_value = default_value[1...-1] if default_value =~ /^['"]/o
0
+ end
0
+ nullable = (status & 8) == 8
0
+ identity = status >= 128
0
+ primary = (sysstat2 & 8) == 8
0
+ ColumnWithIdentity.new(name, default_value, type, nullable, identity, primary)
0
         end
0
- indexes
0
       end
0
 
0
       def quoted_true
0
@@ -302,7 +316,7 @@ module ActiveRecord
0
       def add_limit_offset!(sql, options) # :nodoc:
0
         @limit = options[:limit]
0
         @offset = options[:offset]
0
- if !normal_select?
0
+ if use_temp_table?
0
           # Use temp table to hack offset with Sybase
0
           sql.sub!(/ FROM /i, ' INTO #artemp FROM ')
0
         elsif zero_limit?
0
@@ -318,6 +332,11 @@ module ActiveRecord
0
         end
0
       end
0
 
0
+ def add_lock!(sql, options) #:nodoc:
0
+ @logger.info "Warning: Sybase :lock option '#{options[:lock].inspect}' not supported" if @logger && options.has_key?(:lock)
0
+ sql
0
+ end
0
+
0
       def supports_migrations? #:nodoc:
0
         true
0
       end
0
@@ -334,13 +353,14 @@ module ActiveRecord
0
         begin
0
           execute "ALTER TABLE #{table_name} MODIFY #{column_name} #{type_to_sql(type, options[:limit])}"
0
         rescue StatementInvalid => e
0
- # Swallow exception if no-op.
0
+ # Swallow exception and reset context if no-op.
0
           raise e unless e.message =~ /no columns to drop, add or modify/
0
+ @connection.context.reset
0
         end
0
 
0
- if options[:default]
0
+ if options.has_key?(:default)
0
           remove_default_constraint(table_name, column_name)
0
- execute "ALTER TABLE #{table_name} REPLACE #{column_name} DEFAULT #{options[:default]}"
0
+ execute "ALTER TABLE #{table_name} REPLACE #{column_name} DEFAULT #{quote options[:default]}"
0
         end
0
       end
0
 
0
@@ -350,10 +370,10 @@ module ActiveRecord
0
       end
0
 
0
       def remove_default_constraint(table_name, column_name)
0
- defaults = select "select def.name from sysobjects def, syscolumns col, sysobjects tab where col.cdefault = def.id and col.name = '#{column_name}' and tab.name = '#{table_name}' and col.id = tab.id"
0
- defaults.each {|constraint|
0
+ sql = "select def.name from sysobjects def, syscolumns col, sysobjects tab where col.cdefault = def.id and col.name = '#{column_name}' and tab.name = '#{table_name}' and col.id = tab.id"
0
+ select(sql).each do |constraint|
0
           execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint["name"]}"
0
- }
0
+ end
0
       end
0
 
0
       def remove_index(table_name, options = {})
0
@@ -418,34 +438,44 @@ module ActiveRecord
0
         end
0
       end
0
 
0
- def normal_select?
0
- # If limit is not set at all, we can ignore offset;
0
- # if limit *is* set but offset is zero, use normal select
0
- # with simple SET ROWCOUNT. Thus, only use the temp table
0
- # if limit is set and offset > 0.
0
- has_limit = !@limit.nil?
0
- has_offset = !@offset.nil? && @offset > 0
0
- !has_limit || !has_offset
0
+ # If limit is not set at all, we can ignore offset;
0
+ # if limit *is* set but offset is zero, use normal select
0
+ # with simple SET ROWCOUNT. Thus, only use the temp table
0
+ # if limit is set and offset > 0.
0
+ def use_temp_table?
0
+ !@limit.nil? && !@offset.nil? && @offset > 0
0
       end
0
 
0
       def zero_limit?
0
         !@limit.nil? && @limit == 0
0
       end
0
 
0
- # Select limit number of rows starting at optional offset.
0
- def select(sql, name = nil)
0
- @connection.context.reset
0
+ def raw_execute(sql, name = nil)
0
         log(sql, name) do
0
- if normal_select?
0
- # If limit is not explicitly set, return all results.
0
- @logger.debug "Setting row count to (#{@limit || 'off'})" if @logger
0
-
0
- # Run a normal select
0
- @connection.set_rowcount(@limit || 0)
0
+ @connection.context.reset
0
+ @logger.debug "Setting row count to (#{@limit})" if @logger && @limit
0
+ @connection.set_rowcount(@limit || 0)
0
+ if sql =~ /^\s*SELECT/i
0
             @connection.sql(sql)
0
           else
0
+ @connection.sql_norow(sql)
0
+ end
0
+ @limit = @offset = nil
0
+ if @connection.cmd_fail? or @connection.context.failed?
0
+ raise "SQL Command Failed for #{name}: #{sql}\nMessage: #{@connection.context.message}"
0
+ end
0
+ end
0
+ end
0
+
0
+ # Select limit number of rows starting at optional offset.
0
+ def select(sql, name = nil)
0
+ if !use_temp_table?
0
+ execute(sql, name)
0
+ else
0
+ log(sql, name) do
0
             # Select into a temp table and prune results
0
             @logger.debug "Selecting #{@limit + (@offset || 0)} or fewer rows into #artemp" if @logger
0
+ @connection.context.reset
0
             @connection.set_rowcount(@limit + (@offset || 0))
0
             @connection.sql_norow(sql) # Select into temp table
0
             @logger.debug "Deleting #{@offset || 0} or fewer rows from #artemp" if @logger
0
@@ -456,23 +486,21 @@ module ActiveRecord
0
           end
0
         end
0
 
0
+ raise StatementInvalid, "SQL Command Failed for #{name}: #{sql}\nMessage: #{@connection.context.message}" if @connection.context.failed? or @connection.cmd_fail?
0
+
0
         rows = []
0
- if @connection.context.failed? or @connection.cmd_fail?
0
- raise StatementInvalid, "SQL Command Failed for #{name}: #{sql}\nMessage: #{@connection.context.message}"
0
- else
0
- results = @connection.top_row_result
0
- if results && results.rows.length > 0
0
- fields = results.columns.map { |column| column.sub(/_$/, '') }
0
- results.rows.each do |row|
0
- hashed_row = {}
0
- row.zip(fields) { |cell, column| hashed_row[column] = cell }
0
- rows << hashed_row
0
- end
0
+ results = @connection.top_row_result
0
+ if results && results.rows.length > 0
0
+ fields = results.columns.map { |column| column.sub(/_$/, '') }
0
+ results.rows.each do |row|
0
+ hashed_row = {}
0
+ row.zip(fields) { |cell, column| hashed_row[column] = cell }
0
+ rows << hashed_row
0
           end
0
         end
0
- @connection.sql_norow("drop table #artemp") if !normal_select?
0
+ @connection.sql_norow("drop table #artemp") if use_temp_table?
0
         @limit = @offset = nil
0
- return rows
0
+ rows
0
       end
0
 
0
       def get_table_name(sql)
0
@@ -490,79 +518,42 @@ module ActiveRecord
0
       end
0
 
0
       def get_identity_column(table_name)
0
- @table_columns ||= {}
0
- @table_columns[table_name] ||= columns(table_name)
0
- @table_columns[table_name].each do |col|
0
- return col.name if col.identity
0
+ @id_columns ||= {}
0
+ if !@id_columns.has_key?(table_name)
0
+ @logger.debug "Looking up identity column for table '#{table_name}'" if @logger
0
+ col = columns(table_name).detect { |col| col.identity }
0
+ @id_columns[table_name] = col.nil? ? nil : col.name
0
         end
0
- nil
0
+ @id_columns[table_name]
0
       end
0
 
0
       def query_contains_identity_column(sql, col)
0
         sql =~ /\[#{col}\]/
0
       end
0
 
0
- def table_structure(table_name)
0
- sql = <<SQLTEXT
0
-SELECT col.name AS name, type.name AS type, col.prec, col.scale, col.length,
0
- col.status, obj.sysstat2, def.text
0
- FROM sysobjects obj, syscolumns col, systypes type, syscomments def
0
- WHERE obj.id = col.id AND col.usertype = type.usertype AND col.cdefault *= def.id
0
- AND obj.type = 'U' AND obj.name = '#{table_name}' ORDER BY col.colid
0
-SQLTEXT
0
- log(sql, "Get Column Info ") do
0
- @connection.set_rowcount(0)
0
- @connection.sql(sql)
0
- end
0
- if @connection.context.failed?
0
- raise "SQL Command for table_structure for #{table_name} failed\nMessage: #{@connection.context.message}"
0
- elsif !@connection.cmd_fail?
0
- columns = []
0
- results = @connection.top_row_result
0
- results.rows.each do |row|
0
- name, type, prec, scale, length, status, sysstat2, default = row
0
- type = normalize_type(type, prec, scale, length)
0
- default_value = nil
0
- name.sub!(/_$/o, '')
0
- if default =~ /DEFAULT\s+(.+)/o
0
- default_value = $1.strip
0
- default_value = default_value[1...-1] if default_value =~ /^['"]/o
0
- end
0
- nullable = (status & 8) == 8
0
- identity = status >= 128
0
- primary = (sysstat2 & 8) == 8
0
-
0
- columns << [name, default_value, type, nullable, identity, primary]
0
- end
0
- columns
0
- else
0
- nil
0
- end
0
- end
0
-
0
       # Resolve all user-defined types (udt) to their fundamental types.
0
       def resolve_type(field_type)
0
         (@udts ||= {})[field_type] ||= select_one("sp_help #{field_type}")["Storage_type"].strip
0
       end
0
 
0
       def normalize_type(field_type, prec, scale, length)
0
- if field_type =~ /numeric/i and (scale.nil? or scale == 0)
0
- type = 'int'
0
+ has_scale = (!scale.nil? && scale > 0)
0
+ type = if field_type =~ /numeric/i and !has_scale
0
+ 'int'
0
         elsif field_type =~ /money/i
0
- type = 'numeric'
0
+ 'numeric'
0
         else
0
- type = resolve_type(field_type.strip)
0
+ resolve_type(field_type.strip)
0
         end
0
- size = ''
0
- if prec
0
- size = "(#{prec})"
0
- elsif length && !(type =~ /date|time/)
0
- size = "(#{length})"
0
- end
0
- return type + size
0
- end
0
 
0
- def default_value(value)
0
+ spec = if prec
0
+ has_scale ? "(#{prec},#{scale})" : "(#{prec})"
0
+ elsif length && !(type =~ /date|time|text/)
0
+ "(#{length})"
0
+ else
0
+ ''
0
+ end
0
+ "#{type}#{spec}"
0
       end
0
     end # class SybaseAdapter
0
 
0
@@ -654,10 +645,14 @@ class Fixtures
0
   alias :original_insert_fixtures :insert_fixtures
0
 
0
   def insert_fixtures
0
- values.each do |fixture|
0
- @connection.enable_identity_insert(table_name, true)
0
- @connection.execute "INSERT INTO #{@table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
0
- @connection.enable_identity_insert(table_name, false)
0
+ if @connection.instance_of?(ActiveRecord::ConnectionAdapters::SybaseAdapter)
0
+ values.each do |fixture|
0
+ @connection.enable_identity_insert(table_name, true)
0
+ @connection.execute "INSERT INTO #{@table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
0
+ @connection.enable_identity_insert(table_name, false)
0
+ end
0
+ else
0
+ original_insert_fixtures
0
     end
0
   end
0
 end
...
374
375
376
377
 
378
379
380
...
374
375
376
 
377
378
379
380
0
@@ -374,7 +374,7 @@ class EagerAssociationTest < Test::Unit::TestCase
0
   end
0
   
0
   def test_count_with_include
0
- if current_adapter?(:SQLServerAdapter)
0
+ if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
0
       assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15")
0
     else
0
       assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(comments.body) > 15")
...
574
575
576
577
578
 
 
579
580
581
...
804
805
806
807
808
 
 
809
810
811
...
1027
1028
1029
1030
 
1031
1032
1033
...
574
575
576
 
 
577
578
579
580
581
...
804
805
806
 
 
807
808
809
810
811
...
1027
1028
1029
 
1030
1031
1032
1033
0
@@ -574,8 +574,8 @@ class BasicsTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
- # Oracle and SQLServer do not have a TIME datatype.
0
- unless current_adapter?(:SQLServerAdapter, :OracleAdapter)
0
+ # Oracle, SQLServer, and Sybase do not have a TIME datatype.
0
+ unless current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
0
     def test_utc_as_time_zone
0
       Topic.default_timezone = :utc
0
       attributes = { "bonus_time" => "5:42:00AM" }
0
@@ -804,8 +804,8 @@ class BasicsTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_attributes_on_dummy_time
0
- # Oracle and SQL Server do not have a TIME datatype.
0
- return true if current_adapter?(:SQLServerAdapter, :OracleAdapter)
0
+ # Oracle, SQL Server, and Sybase do not have a TIME datatype.
0
+ return true if current_adapter?(:SQLServerAdapter, :OracleAdapter, :SybaseAdapter)
0
 
0
     attributes = {
0
       "bonus_time" => "5:42:00AM"
0
@@ -1027,7 +1027,7 @@ class BasicsTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_sql_injection_via_find
0
- assert_raises(ActiveRecord::RecordNotFound) do
0
+ assert_raises(ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid) do
0
       Topic.find("123456 OR id > 0")
0
     end
0
   end
...
29
30
31
 
32
...
29
30
31
32
33
0
@@ -29,4 +29,5 @@ DROP TABLE fk_test_has_pk
0
 DROP TABLE keyboards
0
 DROP TABLE legacy_things
0
 DROP TABLE numeric_data
0
+DROP TABLE schema_info
0
 go
...
197
198
199
200
 
201
202
203
204
205
 
206
207
208
...
197
198
199
 
200
201
202
203
204
 
205
206
207
208
0
@@ -197,12 +197,12 @@ CREATE TABLE keyboards (
0
 CREATE TABLE legacy_things (
0
   id numeric(9,0) IDENTITY PRIMARY KEY,
0
   tps_report_number int default NULL,
0
- version int default 0,
0
+ version int default 0
0
 )
0
 
0
 
0
 CREATE TABLE numeric_data (
0
- id numeric((9,0) IDENTITY PRIMARY KEY,
0
+ id numeric(9,0) IDENTITY PRIMARY KEY,
0
   bank_balance numeric(10,2),
0
   big_bank_balance numeric(15,2),
0
   world_population numeric(10),
...
81
82
83
84
 
85
86
 
87
88
89
...
81
82
83
 
84
85
 
86
87
88
89
0
@@ -81,9 +81,9 @@ end
0
 # blocks, so separate script called by Kernel#system is needed.
0
 # (See exec vs. async_exec in the PostgreSQL adapter.)
0
 
0
-# TODO: The SQL Server adapter currently has no support for pessimistic locking
0
+# TODO: The SQL Server and Sybase adapters currently have no support for pessimistic locking
0
 
0
-unless current_adapter?(:SQLServerAdapter)
0
+unless current_adapter?(:SQLServerAdapter, :SybaseAdapter)
0
   class PessimisticLockingTest < Test::Unit::TestCase
0
     self.use_transactional_fixtures = false
0
     fixtures :people, :readers
...
58
59
60
61
62
 
 
63
64
65
...
189
190
191
 
192
 
193
194
195
...
368
369
370
 
371
 
372
373
374
...
389
390
391
 
392
 
393
394
395
...
58
59
60
 
 
61
62
63
64
65
...
189
190
191
192
193
194
195
196
197
...
370
371
372
373
374
375
376
377
378
...
393
394
395
396
397
398
399
400
401
0
@@ -58,8 +58,8 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       assert_nothing_raised { Person.connection.add_index("people", "last_name") }
0
       assert_nothing_raised { Person.connection.remove_index("people", "last_name") }
0
 
0
- # Orcl nds shrt indx nms.
0
- unless current_adapter?(:OracleAdapter)
0
+ # Orcl nds shrt indx nms. Sybs 2.
0
+ unless current_adapter?(:OracleAdapter, :SybaseAdapter)
0
         assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
0
         assert_nothing_raised { Person.connection.remove_index("people", :column => ["last_name", "first_name"]) }
0
         assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) }
0
@@ -189,7 +189,9 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       end
0
       
0
       con = Person.connection
0
+ Person.connection.enable_identity_insert("testings", true) if current_adapter?(:SybaseAdapter)
0
       Person.connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}) values (1, 'hello')"
0
+ Person.connection.enable_identity_insert("testings", false) if current_adapter?(:SybaseAdapter)
0
       assert_nothing_raised {Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default" }
0
 
0
       assert_raises(ActiveRecord::StatementInvalid) do
0
@@ -368,7 +370,9 @@ if ActiveRecord::Base.connection.supports_migrations?
0
 
0
         # Using explicit id in insert for compatibility across all databases
0
         con = ActiveRecord::Base.connection
0
+ con.enable_identity_insert("octopi", true) if current_adapter?(:SybaseAdapter)
0
         assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" }
0
+ con.enable_identity_insert("octopi", false) if current_adapter?(:SybaseAdapter)
0
 
0
         assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', ActiveRecord::Base.connection.select_value("SELECT url FROM octopi WHERE id=1")
0
 
0
@@ -389,7 +393,9 @@ if ActiveRecord::Base.connection.supports_migrations?
0
 
0
         # Using explicit id in insert for compatibility across all databases
0
         con = ActiveRecord::Base.connection
0
+ con.enable_identity_insert("octopi", true) if current_adapter?(:SybaseAdapter)
0
         assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" }
0
+ con.enable_identity_insert("octopi", false) if current_adapter?(:SybaseAdapter)
0
 
0
         assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', ActiveRecord::Base.connection.select_value("SELECT url FROM octopi WHERE id=1")
0
         assert ActiveRecord::Base.connection.indexes(:octopi).first.columns.include?("url")

Comments

    No one has commented yet.