Class Sequel::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_RE = /\Acould not receive data from server: Software caused connection abort/

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 PGError is raised and the connection status cannot be determined or it is not OK.

[Source]

     # File lib/sequel/adapters/postgres.rb, line 166
166:       def check_disconnect_errors
167:         begin
168:           yield
169:         rescue PGError =>e
170:           disconnect = false
171:           begin
172:             s = status
173:           rescue PGError
174:             disconnect = true
175:           end
176:           status_ok = (s == Adapter::CONNECTION_OK)
177:           disconnect ||= !status_ok
178:           disconnect ||= e.message =~ DISCONNECT_ERROR_RE
179:           disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
180:         ensure
181:           block if status_ok
182:         end
183:       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 187
187:       def execute(sql, args=nil)
188:         args = args.map{|v| @db.bound_variable_arg(v, self)} if args
189:         q = check_disconnect_errors{execute_query(sql, args)}
190:         begin
191:           block_given? ? yield(q) : q.cmd_tuples
192:         ensure
193:           q.clear if q
194:         end
195:       end

[Validate]