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.

Methods

Constants

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.

Attributes

prepared_statements  [R]  Hash of prepared statements for this connection. Keys are string names of the server side prepared statement, and values are SQL strings.

Public Instance methods

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.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 148
148:       def check_disconnect_errors
149:         begin
150:           yield
151:         rescue *DISCONNECT_ERROR_CLASSES => e
152:           disconnect = true
153:           raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
154:         rescue PGError => e
155:           disconnect = false
156:           begin
157:             s = status
158:           rescue PGError
159:             disconnect = true
160:           end
161:           status_ok = (s == Adapter::CONNECTION_OK)
162:           disconnect ||= !status_ok
163:           disconnect ||= e.message =~ DISCONNECT_ERROR_RE
164:           disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
165:         ensure
166:           block if status_ok && !disconnect
167:         end
168:       end

Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 172
172:       def execute(sql, args=nil)
173:         args = args.map{|v| @db.bound_variable_arg(v, self)} if args
174:         q = check_disconnect_errors{execute_query(sql, args)}
175:         begin
176:           block_given? ? yield(q) : q.cmd_tuples
177:         ensure
178:           q.clear if q && q.respond_to?(:clear)
179:         end
180:       end

[Validate]