class Sequel::Postgres::Adapter

  1. lib/sequel/adapters/postgres.rb
Superclass: PGconn

PGconn subclass for connection specific methods used with the pg or postgres-pr driver.

Constants

CONNECTION_OK = -1  

Handle old postgres-pr sequel-postgres-pr already implements this API

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.

Public Instance Aliases

async_exec_params -> async_exec

Public Instance methods

async_exec(sql)
[show source]
    # File lib/sequel/adapters/postgres.rb
111 def async_exec(sql)
112   PGresult.new(@conn.query(sql))
113 end
block(timeout=nil)
[show source]
    # File lib/sequel/adapters/postgres.rb
115 def block(timeout=nil)
116 end
check_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.

[show source]
    # File lib/sequel/adapters/postgres.rb
135 def check_disconnect_errors
136   yield
137 rescue *DISCONNECT_ERROR_CLASSES => e
138   disconnect = true
139   raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
140 rescue PGError => e
141   disconnect = false
142   begin
143     s = status
144   rescue PGError
145     disconnect = true
146   end
147   status_ok = (s == Adapter::CONNECTION_OK)
148   disconnect ||= !status_ok
149   disconnect ||= e.message =~ DISCONNECT_ERROR_RE
150   disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
151 ensure
152   block if status_ok && !disconnect
153 end
escape_bytea(str)

Escape bytea values. Uses historical format instead of hex format for maximum compatibility.

[show source]
    # File lib/sequel/adapters/postgres.rb
 99 def escape_bytea(str)
100   str.gsub(/[\000-\037\047\134\177-\377]/n){|b| "\\#{sprintf('%o', b.each_byte{|x| break x}).rjust(3, '0')}"}
101 end
escape_string(str)

Escape strings by doubling apostrophes. This only works if standard conforming strings are used.

[show source]
    # File lib/sequel/adapters/postgres.rb
105 def escape_string(str)
106   str.gsub("'", "''")
107 end
execute(sql, args=nil)

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

[show source]
    # File lib/sequel/adapters/postgres.rb
157 def execute(sql, args=nil)
158   args = args.map{|v| @db.bound_variable_arg(v, self)} if args
159   q = check_disconnect_errors{execute_query(sql, args)}
160   begin
161     defined?(yield) ? yield(q) : q.cmd_tuples
162   ensure
163     q.clear if q && q.respond_to?(:clear)
164   end
165 end
status()
[show source]
    # File lib/sequel/adapters/postgres.rb
118 def status
119   CONNECTION_OK
120 end