Class: Sequel::Postgres::Adapter

Inherits:
PGconn
  • Object
show all
Includes:
AdapterMethods
Defined in:
lib/sequel/lib/sequel/adapters/postgres.rb

Overview

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

Constant Summary

Constants included from AdapterMethods

Sequel::Postgres::AdapterMethods::SELECT_CURRVAL, Sequel::Postgres::AdapterMethods::SELECT_CUSTOM_SEQUENCE, Sequel::Postgres::AdapterMethods::SELECT_PK, Sequel::Postgres::AdapterMethods::SELECT_SERIAL_SEQUENCE

Instance Attribute Summary collapse

Attributes included from AdapterMethods

#db, #transaction_depth

Instance Method Summary collapse

Methods included from AdapterMethods

#last_insert_id, #primary_key, #sequence

Instance Attribute Details

#prepared_statementsObject (readonly)

Returns the value of attribute prepared_statements


126
127
128
# File 'lib/sequel/lib/sequel/adapters/postgres.rb', line 126

def prepared_statements
  @prepared_statements
end

Instance Method Details

#apply_connection_settingsObject

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.


131
132
133
134
135
136
137
138
139
# File 'lib/sequel/lib/sequel/adapters/postgres.rb', line 131

def apply_connection_settings
  super
  if Postgres.use_iso_date_format
    sql = "SET DateStyle = 'ISO'"
    @db.log_info(sql)
    execute(sql)
  end
  @prepared_statements = {} if SEQUEL_POSTGRES_USES_PG
end

#execute(sql, args = nil) ⇒ Object

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


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/sequel/lib/sequel/adapters/postgres.rb', line 143

def execute(sql, args=nil)
  q = nil
  begin
    q = args ? async_exec(sql, args) : async_exec(sql)
  rescue PGError => e
    begin
      s = status
    rescue PGError
      raise Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)
    end
    status_ok = (s == Adapter::CONNECTION_OK)
    status_ok ? raise : Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)
  ensure
    block if status_ok
  end
  begin
    block_given? ? yield(q) : q.cmd_tuples
  ensure
    q.clear
  end
end