Class Sequel::Postgres::Adapter
In: lib/sequel/adapters/postgres.rb
Parent: PGconn

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

Methods

Classes and Modules

Class Sequel::Postgres::Adapter::PGresult

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.
CONNECTION_OK = -1   Make postgres-pr look like pg

External Aliases

close -> finish

Public Instance methods

[Source]

    # File lib/sequel/adapters/postgres.rb, line 84
84:         def async_exec(sql)
85:           PGresult.new(@conn.query(sql))
86:         end

[Source]

    # File lib/sequel/adapters/postgres.rb, line 88
88:         def block(timeout=nil)
89:         end

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 107
107:       def check_disconnect_errors
108:         begin
109:           yield
110:         rescue *DISCONNECT_ERROR_CLASSES => e
111:           disconnect = true
112:           raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
113:         rescue PGError => e
114:           disconnect = false
115:           begin
116:             s = status
117:           rescue PGError
118:             disconnect = true
119:           end
120:           status_ok = (s == Adapter::CONNECTION_OK)
121:           disconnect ||= !status_ok
122:           disconnect ||= e.message =~ DISCONNECT_ERROR_RE
123:           disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
124:         ensure
125:           block if status_ok && !disconnect
126:         end
127:       end

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

[Source]

    # File lib/sequel/adapters/postgres.rb, line 72
72:         def escape_bytea(str)
73:           str.gsub(/[\000-\037\047\134\177-\377]/n){|b| "\\#{sprintf('%o', b.each_byte{|x| break x}).rjust(3, '0')}"}
74:         end

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

[Source]

    # File lib/sequel/adapters/postgres.rb, line 78
78:         def escape_string(str)
79:           str.gsub("'", "''")
80:         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 131
131:       def execute(sql, args=nil)
132:         args = args.map{|v| @db.bound_variable_arg(v, self)} if args
133:         q = check_disconnect_errors{execute_query(sql, args)}
134:         begin
135:           block_given? ? yield(q) : q.cmd_tuples
136:         ensure
137:           q.clear if q && q.respond_to?(:clear)
138:         end
139:       end

[Source]

    # File lib/sequel/adapters/postgres.rb, line 91
91:         def status
92:           CONNECTION_OK
93:         end

[Validate]