Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Oracle: active? check pings the database rather than testing the last…

… command status. References #428.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3189 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 14d50e9da3bb67a881afc2aed2662b5c10005eec 1 parent 87c3287
@jeremy jeremy authored
View
2  activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Oracle: active? check pings the database rather than testing the last command status. #428 [Michael Schoen]
+
* SQLServer: resolve column aliasing/quoting collision when using limit or offset in an eager find. #2974 [kajism@yahoo.com]
* Reloading a model doesn't lose track of its connection. #2996 [junk@miriamtech.com, Jeremy Kemper]
View
32 activerecord/lib/active_record/connection_adapters/oci_adapter.rb
@@ -116,7 +116,7 @@ def cast_to_time(value)
return value if value.is_a? Time
time_array = ParseDate.parsedate value
time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
- Time.send Base.default_timezone, *time_array
+ Time.send(Base.default_timezone, *time_array) rescue nil
end
def guess_date_or_time(value)
@@ -215,20 +215,20 @@ def quote(value, column = nil) #:nodoc:
# Returns true if the connection is active.
def active?
- # Just checks the active flag, which is set false if the last exec
- # got an error indicating a bad connection. An alternative would be
- # to call #ping, which is more expensive (and should always get
- # the same result).
- @connection.active?
+ # Pings the connection to check if it's still good. Note that an
+ # #active? method is also available, but that simply returns the
+ # last known state, which isn't good enough if the connection has
+ # gone stale since the last use.
+ @connection.ping
+ rescue OCIError
+ false
end
# Reconnects to the database.
def reconnect!
- begin
- @connection.reset!
- rescue OCIError => e
- @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}"
- end
+ @connection.reset!
+ rescue OCIError => e
+ @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}"
end
@@ -551,13 +551,11 @@ def initialize(config, factory = OCIConnectionFactory.new)
# checks the connection, while #active? simply returns the last
# known state.
def ping
+ @connection.commit
@active = true
- begin
- @connection.commit
- rescue
- @active = false
- end
- active?
+ rescue
+ @active = false
+ raise
end
# Resets connection, by logging off and creating a new connection.
Please sign in to comment.
Something went wrong with that request. Please try again.