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_CLASSES | = | [IOError, Errno::EPIPE, Errno::ECONNRESET] | The underlying exception classes to reraise as disconnect errors instead of regular database errors. | |
DISCONNECT_ERROR_RE | = | /\A#{Regexp.union(disconnect_errors)}/ | Since exception class based disconnect checking may not work, also trying parsing the exception message to look for disconnect errors. |
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 141 141: def check_disconnect_errors 142: begin 143: yield 144: rescue *DISCONNECT_ERROR_CLASSES => e 145: disconnect = true 146: raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) 147: rescue PGError => e 148: disconnect = false 149: begin 150: s = status 151: rescue PGError 152: disconnect = true 153: end 154: status_ok = (s == Adapter::CONNECTION_OK) 155: disconnect ||= !status_ok 156: disconnect ||= e.message =~ DISCONNECT_ERROR_RE 157: disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise 158: ensure 159: block if status_ok && !disconnect 160: end 161: 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 165 165: def execute(sql, args=nil) 166: args = args.map{|v| @db.bound_variable_arg(v, self)} if args 167: q = check_disconnect_errors{execute_query(sql, args)} 168: begin 169: block_given? ? yield(q) : q.cmd_tuples 170: ensure 171: q.clear if q && q.respond_to?(:clear) 172: end 173: end