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

Ticket #428: oci_ping.patch

File oci_ping.patch, 2.2 kB (added by mschoen, 3 years ago)

makes Oracle work w/ latest approach

  • activerecord/lib/active_record/connection_adapters/oci_adapter.rb

    old new  
    116116          return value if value.is_a? Time 
    117117          time_array = ParseDate.parsedate value 
    118118          time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1; 
    119           Time.send Base.default_timezone, *time_array 
     119          Time.send(Base.default_timezone, *time_array) rescue nil 
    120120        end 
    121121 
    122122        def guess_date_or_time(value) 
     
    215215 
    216216        # Returns true if the connection is active. 
    217217        def active? 
    218           # Just checks the active flag, which is set false if the last exec 
    219           # got an error indicating a bad connection. An alternative would be 
    220           # to call #ping, which is more expensive (and should always get 
    221           # the same result). 
    222           @connection.active? 
     218          # Pings the connection to check if it's still good. Note that an 
     219          # #active? method is also available, but that simply returns the  
     220          # last known state, which isn't good enough if the connection has 
     221          # gone stale since the last use. 
     222          @connection.ping 
     223        rescue OCIError 
     224          false 
    223225        end 
    224226 
    225227        # Reconnects to the database. 
    226228        def reconnect! 
    227           begin 
    228             @connection.reset! 
    229           rescue OCIError => e 
    230             @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}" 
    231           end 
     229          @connection.reset! 
     230        rescue OCIError => e 
     231          @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}" 
    232232        end 
    233233 
    234234 
     
    551551    # checks the connection, while #active? simply returns the last 
    552552    # known state. 
    553553    def ping 
     554      @connection.commit 
    554555      @active = true 
    555       begin 
    556         @connection.commit 
    557       rescue 
    558         @active = false 
    559       end 
    560       active? 
     556    rescue 
     557      @active = false 
     558      raise 
    561559    end 
    562560 
    563561    # Resets connection, by logging off and creating a new connection.