| 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.
| DISCONNECT_ERROR_RE | = | /\Acould not receive data from server: Software caused connection abort/ |
Apply connection settings for this connection. Current sets the date style to ISO in order make Date object creation in ruby faster, if Postgres.use_iso_date_format is true.
# File lib/sequel/adapters/postgres.rb, line 148
148: def apply_connection_settings
149: super
150: if Postgres.use_iso_date_format
151: sql = "SET DateStyle = 'ISO'"
152: execute(sql)
153: end
154: @prepared_statements = {} if SEQUEL_POSTGRES_USES_PG
155: end
Raise a Sequel::DatabaseDisconnectError if a PGError is raised and the connection status cannot be determined or it is not OK.
# File lib/sequel/adapters/postgres.rb, line 159
159: def check_disconnect_errors
160: begin
161: yield
162: rescue PGError =>e
163: disconnect = false
164: begin
165: s = status
166: rescue PGError
167: disconnect = true
168: end
169: status_ok = (s == Adapter::CONNECTION_OK)
170: disconnect ||= !status_ok
171: disconnect ||= e.message =~ DISCONNECT_ERROR_RE
172: disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
173: ensure
174: block if status_ok
175: end
176: 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 180
180: def execute(sql, args=nil)
181: q = check_disconnect_errors{@db.log_yield(sql, args){args ? async_exec(sql, args) : async_exec(sql)}}
182: begin
183: block_given? ? yield(q) : q.cmd_tuples
184: ensure
185: q.clear if q
186: end
187: end