Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2761

Show
Ignore:
Timestamp:
10/27/05 08:18:41 (3 years ago)
Author:
david
Message:

Refactor DB exceptions and deal more with DB2 (closes #2624)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r2748 r2761  
    55* Fixed handling of nil number columns on Oracle and cleaned up tests for Oracle in general #2555 [schoenm@earthlink.net] 
    66 
    7 * Added quoted_true and quoted_false methods to db2_adapter and cleaned up tests for DB2 #2493 [maik schmidt] 
     7* Added quoted_true and quoted_false methods and tables to db2_adapter and cleaned up tests for DB2 #2493, #2624 [maik schmidt] 
    88 
    99 
  • trunk/activerecord/lib/active_record/associations.rb

    r2744 r2761  
    894894            construct_finder_sql_for_association_limiting(options), 
    895895            "#{name} Load IDs For Limited Eager Loading" 
    896           ).collect { |id| "'#{id}'" }.join(", ") 
     896          ).collect { |id| connection.quote(id) }.join(", ") 
    897897        end 
    898898 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

    r2614 r2761  
    3434      end 
    3535       
    36       # Does this adapter support migrations ?  Backend specific, as the 
     36      # Does this adapter support migrations?  Backend specific, as the 
    3737      # abstract adapter always returns +false+. 
    3838      def supports_migrations? 
  • trunk/activerecord/lib/active_record/connection_adapters/db2_adapter.rb

    r2739 r2761  
    1 # Author: Maik Schmidt <contact@maik-schmidt.de> 
     1# Author/Maintainer: Maik Schmidt <contact@maik-schmidt.de> 
    22 
    33require 'active_record/connection_adapters/abstract_adapter' 
     
    114114        end 
    115115 
     116        def tables(name = nil) 
     117          stmt = DB2::Statement.new(@connection) 
     118          result = [] 
     119          stmt.tables.each { |t| result << t[2].downcase } 
     120          stmt.free 
     121          result 
     122        end 
     123 
    116124        def columns(table_name, name = nil) 
    117125          stmt = DB2::Statement.new(@connection) 
  • trunk/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb

    r2586 r2761  
    1111# Modifications (ODBC): Mark Imbriaco <mark.imbriaco@pobox.com> 
    1212# Date: 6/26/2005 
     13# 
     14# Current maintainer: Ryan Tomayko <rtomayko@gmail.com> 
    1315# 
    1416module ActiveRecord 
  • trunk/activerecord/test/abstract_unit.rb

    r2416 r2761  
    1818  end 
    1919end 
     20 
     21def current_adapter?(type) 
     22  ActiveRecord::ConnectionAdapters.const_defined?(type) && 
     23    ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type)) 
     24end 
  • trunk/activerecord/test/associations_test.rb

    r2705 r2761  
    11521152    # SQL Server doesn't have a separate column type just for dates,  
    11531153    # so the time is in the string and incorrectly formatted 
    1154     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
     1154    if current_adapter?(:SQLServerAdapter) 
    11551155      kenReloaded.projects.each { |prj| assert_equal(sqlnow, prj.joined_on.strftime("%Y/%m/%d 00:00:00")) } 
    11561156    else 
     
    12461246    # SQL Server doesn't have a separate column type just for dates,  
    12471247    # so the time is in the string and incorrectly formatted 
    1248     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
     1248    if current_adapter?(:SQLServerAdapter) 
    12491249      assert_equal Time.mktime(2004, 10, 10).strftime("%Y/%m/%d 00:00:00"), Time.parse(Developer.find(1).projects.first.joined_on).strftime("%Y/%m/%d 00:00:00") 
    12501250    else 
     
    12671267    # SQL Server doesn't have a separate column type just for dates,  
    12681268    # so the time is in the string and incorrectly formatted 
    1269     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
     1269    if current_adapter?(:SQLServerAdapter) 
    12701270      assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), Time.parse(jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on).strftime("%Y/%m/%d 00:00:00") 
    12711271      assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), Time.parse(developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on).strftime("%Y/%m/%d 00:00:00") 
  • trunk/activerecord/test/base_test.rb

    r2748 r2761  
    116116  end 
    117117  
    118   def test_attributes_hash 
     118  def test_case_sensitive_attributes_hash 
     119    # DB2 is not case-sensitive 
     120    return true if current_adapter?(:DB2Adapter) 
     121 
    119122    assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.find(:first).attributes 
    120123  end 
     
    221224  def test_preserving_date_objects 
    222225    # SQL Server doesn't have a separate column type just for dates, so all are returned as time 
    223     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter 
    224       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
    225     end 
     226    return true if current_adapter?(:SQLServerAdapter) 
    226227 
    227228    assert_kind_of( 
     
    229230      "The last_read attribute should be of the Date class" 
    230231    ) 
    231  
     232  end 
     233 
     234  def test_preserving_time_objects 
    232235    # Oracle does not have a TIME datatype. 
    233     if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter 
    234       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter) 
    235     end 
     236    return true if current_adapter?(:OCIAdapter) 
     237 
    236238    assert_kind_of( 
    237239      Time, Topic.find(1).bonus_time, 
    238240      "The bonus_time attribute should be of the Time class" 
    239241    ) 
    240   end 
    241  
    242   def test_preserving_time_objects 
     242 
    243243    assert_kind_of( 
    244244      Time, Topic.find(1).written_on, 
     
    385385  def test_update_all 
    386386    # The ADO library doesn't support the number of affected rows 
    387     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter 
    388       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
    389     end 
     387    return true if current_adapter?(:SQLServerAdapter) 
     388 
    390389    assert_equal 2, Topic.update_all("content = 'bulk updated!'") 
    391390    assert_equal "bulk updated!", Topic.find(1).content 
     
    407406  def test_delete_all 
    408407    # The ADO library doesn't support the number of affected rows 
    409     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter 
    410       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
    411     end 
     408    return true if current_adapter?(:SQLServerAdapter) 
     409 
    412410    assert_equal 2, Topic.delete_all 
    413411  end 
     
    472470  end 
    473471 
    474   # Oracle and SQLServer do not have a TIME datatype. 
    475   unless 'OCI' == ActiveRecord::Base.connection.adapter_name or ActiveRecord::ConnectionAdapters.const_defined?(:SQLServerAdapter) 
    476     def test_utc_as_time_zone 
    477       Topic.default_timezone = :utc 
    478       attributes = { "bonus_time" => "5:42:00AM" } 
    479       topic = Topic.find(1) 
    480       topic.attributes = attributes 
    481       assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time 
    482       Topic.default_timezone = :local 
    483     end 
     472  def test_utc_as_time_zone 
     473    # Oracle and SQLServer do not have a TIME datatype. 
     474    return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter) 
     475 
     476    Topic.default_timezone = :utc 
     477    attributes = { "bonus_time" => "5:42:00AM" } 
     478    topic = Topic.find(1) 
     479    topic.attributes = attributes 
     480    assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time 
     481    Topic.default_timezone = :local 
    484482  end 
    485483 
     
    588586  def test_multiparameter_attributes_on_date 
    589587    # SQL Server doesn't have a separate column type just for dates, so all are returned as time 
    590     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter 
    591       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
    592     end 
     588    return true if current_adapter?(:SQLServerAdapter) 
    593589 
    594590    attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" } 
     
    602598  def test_multiparameter_attributes_on_date_with_empty_date 
    603599    # SQL Server doesn't have a separate column type just for dates, so all are returned as time 
    604     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter 
    605       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
    606     end 
     600    return true if current_adapter?(:SQLServerAdapter) 
    607601 
    608602    attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "" } 
     
    651645 
    652646  def test_attributes_on_dummy_time 
    653     # Oracle does not have a TIME datatype. 
    654     if ActiveRecord::ConnectionAdapters.const_defined? :OCIAdapter 
    655       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OCIAdapter) 
    656     end 
    657     # Sqlserver doesn't either . 
    658     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter 
    659       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
    660     end 
     647    # Oracle and SQL Server does not have a TIME datatype. 
     648    return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter) 
    661649 
    662650    attributes = { 
     
    739727 
    740728  # TODO: extend defaults tests to other databases! 
    741   if 'PostgreSQL' == ActiveRecord::Base.connection.adapter_name 
     729  if current_adapter?(:PostgreSQLAdapter) 
    742730    def test_default 
    743731      default = Default.new 
     
    10871075   
    10881076  private 
    1089  
    10901077    def assert_readers(model, exceptions) 
    10911078      expected_readers = model.column_names - (model.serialized_attributes.keys + exceptions + ['id']) 
  • trunk/activerecord/test/deprecated_finder_test.rb

    r2625 r2761  
    1616 
    1717  def test_find_all_with_prepared_limit_and_offset 
    18     if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter 
    19       if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter) 
    20         assert_raises(ArgumentError) { Entrant.find_all nil, "id ASC", [2, 1] } 
    21       end 
     18    if current_adapter?(:OCIAdapter) 
     19      assert_raises(ArgumentError) { Entrant.find_all nil, "id ASC", [2, 1] } 
    2220    else 
    2321      entrants = Entrant.find_all nil, "id ASC", [2, 1] 
  • trunk/activerecord/test/fixtures_test.rb

    r2741 r2761  
    5454  def test_inserts_with_pre_and_suffix 
    5555    # not supported yet in OCI adapter 
    56     if ActiveRecord::ConnectionAdapters.const_defined? :OCIAdapter 
    57       return true if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OCIAdapter) 
    58     end 
     56    return true if current_adapter?(:OCIAdapter) 
    5957 
    6058    ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t| 
  • trunk/activerecord/test/inheritance_test.rb

    r2595 r2761  
    99  def test_a_bad_type_column 
    1010    #SQLServer need to turn Identity Insert On before manually inserting into the Identity column 
    11     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
     11    if current_adapter?(:SQLServerAdapter) 
    1212      Company.connection.execute "SET IDENTITY_INSERT companies ON" 
    1313    end 
    1414    Company.connection.insert "INSERT INTO companies (id, type, name) VALUES(100, 'bad_class!', 'Not happening')" 
     15 
    1516    #We then need to turn it back Off before continuing. 
    16     if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) 
     17    if current_adapter?(:SQLServerAdapter) 
    1718      Company.connection.execute "SET IDENTITY_INSERT companies OFF" 
    1819    end 
  • trunk/activerecord/test/schema_dumper_test.rb

    r2741 r2761  
    44 
    55if ActiveRecord::Base.connection.respond_to?(:tables) 
    6  
    7   unless ActiveRecord::ConnectionAdapters.const_defined?(:OCIAdapter) && \ 
    8     ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OCIAdapter) 
     6  unless current_adapter?(:OCIAdapter) 
    97 
    108    class SchemaDumperTest < Test::Unit::TestCase 
     
    2119 
    2220  end 
    23  
    2421end