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: Software caused connection abort/ |
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 109 109: def check_disconnect_errors 110: begin 111: yield 112: rescue PGError =>e 113: disconnect = false 114: begin 115: s = status 116: rescue PGError 117: disconnect = true 118: end 119: status_ok = (s == Adapter::CONNECTION_OK) 120: disconnect ||= !status_ok 121: disconnect ||= e.message =~ DISCONNECT_ERROR_RE 122: disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise 123: ensure 124: block if status_ok 125: end 126: 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 130 130: def execute(sql, args=nil) 131: args = args.map{|v| @db.bound_variable_arg(v, self)} if args 132: q = check_disconnect_errors{execute_query(sql, args)} 133: begin 134: block_given? ? yield(q) : q.cmd_tuples 135: ensure 136: q.clear if q 137: end 138: end