# postgres.rb

Path: | lib/sequel/adapters/shared/postgres.rb
Last Update: | Sat Aug 21 15:13:17 -0600 2010

### Methods

apply_connection_settings last_insert_id primary_key sequence

### Public Instance methods

apply_connection_settings()

Apply connection settings for this connection. Currently, turns standard_conforming_strings ON if Postgres.force_standard_strings is true.

[Source]

         # File lib/sequel/adapters/shared/postgres.rb, line 117
    117:       def apply_connection_settings
    118:         if Postgres.force_standard_strings
    119:           sql = "SET standard_conforming_strings = ON"
    120:           @db.log_info(sql)
    121:           # This setting will only work on PostgreSQL 8.2 or greater
    122:           # and we don't know the server version at this point, so
    123:           # try it unconditionally and rescue any errors.
    124:           execute(sql) rescue nil
    125:         end
    126:         if cmm = Postgres.client_min_messages
    127:           sql = "SET client_min_messages = '#{cmm.to_s.upcase}'"
    128:           @db.log_info(sql)
    129:           execute(sql)
    130:         end
    131:       end

last_insert_id(sequence)

Get the last inserted value for the given sequence.

[Source]

         # File lib/sequel/adapters/shared/postgres.rb, line 134
    134:       def last_insert_id(sequence)
    135:         sql = SELECT_CURRVAL % sequence
    136:         @db.log_info(sql)
    137:         execute(sql) do |r|
    138:           val = single_value(r)
    139:           return val.to_i if val
    140:         end
    141:       end

primary_key(schema, table)

Get the primary key for the given table.

[Source]

         # File lib/sequel/adapters/shared/postgres.rb, line 144
    144:       def primary_key(schema, table)
    145:         sql = SELECT_PK[schema, table]
    146:         @db.log_info(sql)
    147:         execute(sql) do |r|
    148:           return single_value(r)
    149:         end
    150:       end

sequence(schema, table)

Get the primary key and sequence for the given table.

[Source]

         # File lib/sequel/adapters/shared/postgres.rb, line 153
    153:       def sequence(schema, table)
    154:         sql = SELECT_SERIAL_SEQUENCE[schema, table]
    155:         @db.log_info(sql)
    156:         execute(sql) do |r|
    157:           seq = single_value(r)
    158:           return seq if seq
    159:         end
    160:
    161:         sql = SELECT_CUSTOM_SEQUENCE[schema, table]
    162:         @db.log_info(sql)
    163:         execute(sql) do |r|
    164:           return single_value(r)
    165:         end
    166:       end

[Validate]