Revision 5389
Added by Aaron Marcuse-Kubitza about 12 years ago
lib/sql.py | ||
---|---|---|
1052 | 1052 |
return [sql_gen.as_Col(strings.ustr(c), table) |
1053 | 1053 |
for c in table_col_names(db, table, *args, **kw_args)] |
1054 | 1054 |
|
1055 |
def pkey_name(db, table, recover=None): |
|
1056 |
'''If no pkey, returns the first column in the table.''' |
|
1055 |
def table_pkey_col(db, table, recover=None): |
|
1057 | 1056 |
table = sql_gen.as_Table(table) |
1058 | 1057 |
|
1059 | 1058 |
join_cols = ['table_schema', 'table_name', 'constraint_schema', |
... | ... | |
1068 | 1067 |
if schema != None: conds.append(('table_schema', schema)) |
1069 | 1068 |
order_by = 'position_in_unique_constraint' |
1070 | 1069 |
|
1071 |
try: return value(select(db, tables, cols, conds, order_by=order_by, |
|
1072 |
limit=1, log_level=4)) |
|
1070 |
return sql_gen.Col(value(select(db, tables, cols, conds, order_by=order_by, |
|
1071 |
limit=1, log_level=4)), table) |
|
1072 |
|
|
1073 |
def pkey_name(db, table, recover=None): |
|
1074 |
'''If no pkey, returns the first column in the table.''' |
|
1075 |
try: return table_pkey_col(db, table, recover).name |
|
1073 | 1076 |
except StopIteration: return table_col_names(db, table, recover)[0] |
1074 | 1077 |
|
1075 | 1078 |
def pkey_col(db, table, *args, **kw_args): |
Also available in: Unified diff
sql.py: Added table_pkey_col() and use it in pkey_name()