Revision 3005
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
981 | 981 |
table = sql_gen.as_Table(table) |
982 | 982 |
index = sql_gen.Table(str(sql_gen.Col(','.join(map(str, cols)), table))) |
983 | 983 |
|
984 |
str_ = 'CREATE' |
|
985 |
if unique: str_ += ' UNIQUE' |
|
986 |
str_ += ' INDEX '+index.to_str(db)+' ON '+table.to_str(db)+' ('+( |
|
987 |
', '.join((v.to_str(db) for v in exprs)))+')' |
|
988 |
|
|
989 |
try: run_query(db, str_, recover=True, cacheable=True, log_level=3) |
|
990 |
except DuplicateException: pass # index already existed |
|
984 |
# Add index |
|
985 |
while True: |
|
986 |
str_ = 'CREATE' |
|
987 |
if unique: str_ += ' UNIQUE' |
|
988 |
str_ += ' INDEX '+index.to_str(db)+' ON '+table.to_str(db)+' ('+( |
|
989 |
', '.join((v.to_str(db) for v in exprs)))+')' |
|
990 |
|
|
991 |
try: |
|
992 |
run_query(db, str_, recover=True, cacheable=True, log_level=3, |
|
993 |
log_ignore_excs=(DuplicateException,)) |
|
994 |
break |
|
995 |
except DuplicateException: |
|
996 |
index.name = next_version(index.name) |
|
997 |
# try again with next version of name |
|
991 | 998 |
|
992 | 999 |
def add_pkey(db, table, cols=None, recover=None): |
993 | 1000 |
'''Adds a primary key. |
Also available in: Unified diff
sql.py: add_index(): Version index names to avoid collisions