| 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.
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 150
150: def apply_connection_settings
151: super
152: if Postgres.use_iso_date_format
153: sql = "SET DateStyle = 'ISO'"
154: execute(sql)
155: end
156: @prepared_statements = {} if SEQUEL_POSTGRES_USES_PG
157: 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 161
161: def check_disconnect_errors
162: begin
163: yield
164: rescue PGError =>e
165: begin
166: s = status
167: rescue PGError
168: raise Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)
169: end
170: status_ok = (s == Adapter::CONNECTION_OK)
171: status_ok ? raise : raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
172: ensure
173: block if status_ok
174: end
175: 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 179
179: def execute(sql, args=nil)
180: q = check_disconnect_errors{@db.log_yield(sql, args){args ? async_exec(sql, args) : async_exec(sql)}}
181: begin
182: block_given? ? yield(q) : q.cmd_tuples
183: ensure
184: q.clear
185: end
186: end