Revision 2726
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
1020 | 1020 |
cacheable=True)) |
1021 | 1021 |
else: raise NotImplementedError("Can't list tables for "+module+' database') |
1022 | 1022 |
|
1023 |
def table_exists(db, table): |
|
1024 |
table = sql_gen.as_Table(table) |
|
1025 |
return list(tables(db, table.schema, table.name)) != [] |
|
1026 |
|
|
1027 |
def errors_table(db, table, if_exists=True): |
|
1028 |
''' |
|
1029 |
@param if_exists If set, returns None if the errors table doesn't exist |
|
1030 |
@return None|sql_gen.Table |
|
1031 |
''' |
|
1032 |
table = sql_gen.as_Table(table) |
|
1033 |
if table.srcs != (): table = table.srcs[0] |
|
1034 |
|
|
1035 |
errors_table = sql_gen.suffixed_table(table, '.errors') |
|
1036 |
if if_exists and not table_exists(db, errors_table): return None |
|
1037 |
return errors_table |
|
1038 |
|
|
1023 | 1039 |
##### Database management |
1024 | 1040 |
|
1025 | 1041 |
def empty_db(db, schema='public', **kw_args): |
Also available in: Unified diff
sql.py: Added table_exists() and errors_table()