Class | Sequel::Postgres::Adapter |
In: |
lib/sequel/adapters/postgres.rb
|
Parent: | ::PGconn |
PGconn subclass for connection specific methods used with the pg, postgres, or postgres-pr driver.
DISCONNECT_ERROR_RE | = | /\Acould not receive data from server/ |
Raise a Sequel::DatabaseDisconnectError if a PGError is raised and the connection status cannot be determined or it is not OK.
# File lib/sequel/adapters/postgres.rb, line 122 122: def check_disconnect_errors 123: begin 124: yield 125: rescue PGError => e 126: disconnect = false 127: begin 128: s = status 129: rescue PGError 130: disconnect = true 131: end 132: status_ok = (s == Adapter::CONNECTION_OK) 133: disconnect ||= !status_ok 134: disconnect ||= e.message =~ DISCONNECT_ERROR_RE 135: disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise 136: rescue IOError, Errno::EPIPE, Errno::ECONNRESET => e 137: disconnect = true 138: raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) 139: ensure 140: block if status_ok && !disconnect 141: end 142: end
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 146 146: def execute(sql, args=nil) 147: args = args.map{|v| @db.bound_variable_arg(v, self)} if args 148: q = check_disconnect_errors{execute_query(sql, args)} 149: begin 150: block_given? ? yield(q) : q.cmd_tuples 151: ensure 152: q.clear if q && q.respond_to?(:clear) 153: end 154: end