Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

0 comments on commit 83a21f7

Please sign in to comment.
Something went wrong with that request. Please try again.