postgres.rb

Path: lib/sequel_core/adapters/shared/postgres.rb
Last Update: Wed Feb 25 03:52:28 -0700 2009

Methods

Public Instance methods

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

[Source]

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

Get the last inserted value for the given sequence.

[Source]

     # File lib/sequel_core/adapters/shared/postgres.rb, line 130
130:       def last_insert_id(sequence)
131:         sql = SELECT_CURRVAL % sequence
132:         @db.log_info(sql)
133:         execute(sql) do |r|
134:           val = single_value(r)
135:           return val.to_i if val
136:         end
137:       end

Get the primary key for the given table.

[Source]

     # File lib/sequel_core/adapters/shared/postgres.rb, line 140
140:       def primary_key(schema, table)
141:         sql = SELECT_PK[schema, table]
142:         @db.log_info(sql)
143:         execute(sql) do |r|
144:           return single_value(r)
145:         end
146:       end

Get the primary key and sequence for the given table.

[Source]

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

[Validate]