| Class | Sequel::Postgres::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 132
132: def apply_connection_settings
133: super
134: if Postgres.use_iso_date_format
135: sql = "SET DateStyle = 'ISO'"
136: @db.log_info(sql)
137: execute(sql)
138: end
139: @prepared_statements = {} if SEQUEL_POSTGRES_USES_PG
140: 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 144
144: def execute(sql, args=nil)
145: q = nil
146: begin
147: q = args ? async_exec(sql, args) : async_exec(sql)
148: rescue PGError => e
149: begin
150: s = status
151: rescue PGError
152: raise Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)
153: end
154: status_ok = (s == Adapter::CONNECTION_OK)
155: status_ok ? raise : Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)
156: ensure
157: block if status_ok
158: end
159: begin
160: block_given? ? yield(q) : q.cmd_tuples
161: ensure
162: q.clear
163: end
164: end