Revision 2642
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
179 | 179 |
'''A dict that automatically makes inserted entries Col objects''' |
180 | 180 |
|
181 | 181 |
'''For params, see dict()''' |
182 |
def __init__(self, keys_table, *args, **kw_args): |
|
182 |
def __init__(self, db, keys_table, *args, **kw_args):
|
|
183 | 183 |
dict.__init__(self, *args, **kw_args) |
184 | 184 |
|
185 |
self.db = db |
|
185 | 186 |
self.table = keys_table |
186 | 187 |
|
187 | 188 |
def __getitem__(self, key): |
188 | 189 |
return dict.__getitem__(self, self._key(key)) |
189 | 190 |
|
190 | 191 |
def __setitem__(self, key, value): |
191 |
return dict.__setitem__(self, self._key(key), as_Col(value, name=key)) |
|
192 |
key = self._key(key) |
|
193 |
return dict.__setitem__(self, key, as_Col(value, name=key.name)) |
|
192 | 194 |
|
193 | 195 |
def update(self, dict_): |
194 | 196 |
for key, value in dict_.iteritems(): self[key] = value |
lib/sql.py | ||
---|---|---|
859 | 859 |
'''Recovers from errors. |
860 | 860 |
Only works under PostgreSQL (uses INSERT RETURNING). |
861 | 861 |
''' |
862 |
row = sql_gen.ColDict(table, row) |
|
862 |
row = sql_gen.ColDict(db, table, row)
|
|
863 | 863 |
if pkey_ == None: pkey_ = pkey(db, table, recover=True) |
864 | 864 |
|
865 | 865 |
try: |
... | ... | |
922 | 922 |
@return sql_gen.Col Where the output pkeys are made available |
923 | 923 |
''' |
924 | 924 |
out_table = sql_gen.as_Table(out_table) |
925 |
mapping = sql_gen.ColDict(out_table, mapping) |
|
925 |
mapping = sql_gen.ColDict(db, out_table, mapping)
|
|
926 | 926 |
|
927 | 927 |
def log_debug(msg): db.log_debug(msg, level=1.5) |
928 | 928 |
def col_ustr(str_): |
... | ... | |
1017 | 1017 |
insert_in_pkeys = insert_pkeys_table('in') |
1018 | 1018 |
|
1019 | 1019 |
# Do inserts and selects |
1020 |
join_cols = sql_gen.ColDict(out_table) |
|
1020 |
join_cols = sql_gen.ColDict(db, out_table)
|
|
1021 | 1021 |
while True: |
1022 | 1022 |
if limit_ref[0] == 0: # special case |
1023 | 1023 |
log_debug('Creating an empty pkeys table') |
Also available in: Unified diff
sql_gen.py: ColDict: Take a db param for later use in getting default column values