Permalink
Browse files

Firebird: active? and reconnect! methods for handling stale connectio…

…ns. References #428.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3205 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c3612a2 commit 3d0e3c92900ff3dd1ddef7c94c201698e71ca9d5 @jeremy jeremy committed Dec 2, 2005
Showing with 25 additions and 2 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +23 −2 activerecord/lib/active_record/connection_adapters/firebird_adapter.rb
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Firebird: active? and reconnect! methods for handling stale connections. #428 [Ken Kunz <kennethkunz@gmail.com>]
+
* Firebird: updated for FireRuby 0.4.0. #3009 [Ken Kunz <kennethkunz@gmail.com>]
* MySQL and PostgreSQL: active? compatibility with the pure-Ruby driver. #428 [Jeremy Kemper]
View
25 activerecord/lib/active_record/connection_adapters/firebird_adapter.rb
@@ -31,9 +31,10 @@ def firebird_connection(config) # :nodoc:
raise ArgumentError, "No database specified. Missing argument: database."
end
options = config[:charset] ? { CHARACTER_SET => config[:charset] } : {}
+ connection_params = [config[:username], config[:password], options]
db = FireRuby::Database.new_from_params(*config.values_at(:database, :host, :port, :service))
- connection = db.connect(config[:username], config[:password], options)
- ConnectionAdapters::FirebirdAdapter.new(connection, logger)
+ connection = db.connect(*connection_params)
+ ConnectionAdapters::FirebirdAdapter.new(connection, logger, connection_params)
end
end
@@ -240,6 +241,11 @@ class FirebirdAdapter < AbstractAdapter
@@boolean_domain = { :true => 1, :false => 0 }
cattr_accessor :boolean_domain
+ def initialize(connection, logger, connection_params=nil)
+ super(connection, logger)
+ @connection_params = connection_params
+ end
+
def adapter_name # :nodoc:
'Firebird'
end
@@ -254,6 +260,7 @@ def default_sequence_name(table_name, primary_key) # :nodoc:
"#{table_name}_seq"
end
+
# QUOTING ==================================================
def quote(value, column = nil) # :nodoc:
@@ -280,6 +287,19 @@ def quoted_false # :nodoc:
quote(boolean_domain[:false])
end
+
+ # CONNECTION MANAGEMENT ====================================
+
+ def active?
+ not @connection.closed?
+ end
+
+ def reconnect!
+ @connection.close
+ @connection = @connection.database.connect(*@connection_params)
+ end
+
+
# DATABASE STATEMENTS ======================================
def select_all(sql, name = nil) # :nodoc:
@@ -340,6 +360,7 @@ def next_sequence_value(sequence_name)
FireRuby::Generator.new(sequence_name, @connection).next(1)
end
+
# SCHEMA STATEMENTS ========================================
def columns(table_name, name = nil) # :nodoc:

0 comments on commit 3d0e3c9

Please sign in to comment.