| Path: | lib/sequel/adapters/shared/postgres.rb |
| Last Update: | Wed Jul 08 08:35:27 -0600 2009 |
Apply connection settings for this connection. Currently, turns standard_conforming_strings ON if Postgres.force_standard_strings is true.
# File lib/sequel/adapters/shared/postgres.rb, line 115
115: def apply_connection_settings
116: if Postgres.force_standard_strings
117: sql = "SET standard_conforming_strings = ON"
118: @db.log_info(sql)
119: # This setting will only work on PostgreSQL 8.2 or greater
120: # and we don't know the server version at this point, so
121: # try it unconditionally and rescue any errors.
122: execute(sql) rescue nil
123: end
124: if cmm = Postgres.client_min_messages
125: sql = "SET client_min_messages = '#{cmm.to_s.upcase}'"
126: @db.log_info(sql)
127: execute(sql)
128: end
129: end
Get the last inserted value for the given sequence.
# File lib/sequel/adapters/shared/postgres.rb, line 132
132: def last_insert_id(sequence)
133: sql = SELECT_CURRVAL % sequence
134: @db.log_info(sql)
135: execute(sql) do |r|
136: val = single_value(r)
137: return val.to_i if val
138: end
139: end
Get the primary key for the given table.
# File lib/sequel/adapters/shared/postgres.rb, line 142
142: def primary_key(schema, table)
143: sql = SELECT_PK[schema, table]
144: @db.log_info(sql)
145: execute(sql) do |r|
146: return single_value(r)
147: end
148: end
Get the primary key and sequence for the given table.
# File lib/sequel/adapters/shared/postgres.rb, line 151
151: def sequence(schema, table)
152: sql = SELECT_SERIAL_SEQUENCE[schema, table]
153: @db.log_info(sql)
154: execute(sql) do |r|
155: seq = single_value(r)
156: return seq if seq
157: end
158:
159: sql = SELECT_CUSTOM_SEQUENCE[schema, table]
160: @db.log_info(sql)
161: execute(sql) do |r|
162: return single_value(r)
163: end
164: end