Revision 2819
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/sql_gen.py | ||
---|---|---|
274 | 274 |
|
275 | 275 |
def __setitem__(self, key, value): |
276 | 276 |
key = self._key(key) |
277 |
if value == None: value = self.db.col_default(key)
|
|
277 |
if value == None: value = self.db.col_info(key).default
|
|
278 | 278 |
dicts.DictProxy.__setitem__(self, key, as_Col(value, name=key.name)) |
279 | 279 |
|
280 | 280 |
def _key(self, key): return as_Col(key, self.table) |
lib/sql.py | ||
---|---|---|
370 | 370 |
self.log_debug('Autocommitting') |
371 | 371 |
self.db.commit() |
372 | 372 |
|
373 |
def col_default(self, col):
|
|
373 |
def col_info(self, col):
|
|
374 | 374 |
table = sql_gen.Table('columns', 'information_schema') |
375 |
cols = ['data_type', 'column_default', 'is_nullable'] |
|
375 | 376 |
|
376 | 377 |
conds = [('table_name', col.table.name), ('column_name', col.name)] |
377 | 378 |
schema = col.table.schema |
378 | 379 |
if schema != None: conds.append(('table_schema', schema)) |
379 | 380 |
|
380 |
return sql_gen.as_Code(value(select(self, table, ['column_default'],
|
|
381 |
conds, order_by='table_schema', limit=1, log_level=3)), self)
|
|
381 |
type_, default, nullable = row(select(self, table, cols, conds,
|
|
382 |
order_by='table_schema', limit=1, log_level=3))
|
|
382 | 383 |
# TODO: order_by search_path schema order |
384 |
default = sql_gen.as_Code(default, self) |
|
385 |
|
|
386 |
return sql_gen.TypedCol(col.name, type_, default, nullable) |
|
383 | 387 |
|
384 | 388 |
connect = DbConn |
385 | 389 |
|
Also available in: Unified diff
sql.py: DbConn: Renamed col_default() to col_info() and have it return a sql_gen.TypedCol object containing all the TypedCol info about the column, not just the default value