class Sequel::Postgres::Adapter
PGconn subclass for connection specific methods used with the pg, postgres, or postgres-pr driver.
Constants
- DISCONNECT_ERROR_CLASSES
The underlying exception classes to reraise as disconnect errors instead of regular database errors.
- DISCONNECT_ERROR_RE
Since exception class based disconnect checking may not work, also trying parsing the exception message to look for disconnect errors.
Attributes
Public Instance Methods
check_disconnect_errors() { || ... }
click to toggle source
Raise a Sequel::DatabaseDisconnectError if a one of the disconnect error classes is raised, or a PGError is raised and the connection status cannot be determined or it is not OK.
# File lib/sequel/adapters/postgres.rb, line 152 def check_disconnect_errors begin yield rescue *DISCONNECT_ERROR_CLASSES => e disconnect = true raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) rescue PGError => e disconnect = false begin s = status rescue PGError disconnect = true end status_ok = (s == Adapter::CONNECTION_OK) disconnect ||= !status_ok disconnect ||= e.message =~ DISCONNECT_ERROR_RE disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise ensure block if status_ok && !disconnect end end
execute(sql, args=nil) { |q| ... }
click to toggle source
Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.
# File lib/sequel/adapters/postgres.rb, line 176 def execute(sql, args=nil) args = args.map{|v| @db.bound_variable_arg(v, self)} if args q = check_disconnect_errors{execute_query(sql, args)} begin block_given? ? yield(q) : q.cmd_tuples ensure q.clear if q && q.respond_to?(:clear) end end
Private Instance Methods
execute_query(sql, args)
click to toggle source
Return the PGResult object that is returned by executing the given sql and args.
# File lib/sequel/adapters/postgres.rb, line 190 def execute_query(sql, args) @db.log_connection_yield(sql, self, args){args ? async_exec(sql, args) : async_exec(sql)} end