sql: do not try fixing empty sequences

This commit is contained in:
Frédéric Péters 2013-06-12 22:44:28 +02:00
parent 095a134575
commit 1c15b65dd7
1 changed files with 4 additions and 3 deletions

View File

@ -778,9 +778,10 @@ class SqlUser(SqlMixin, wcs.users.User):
sql_statement = '''select max(id) from %s''' % cls._table_name
cur.execute(sql_statement)
max_id = cur.fetchone()[0]
sql_statement = '''ALTER SEQUENCE %s_id_seq RESTART %s''' % (
cls._table_name, max_id+1)
cur.execute(sql_statement)
if max_id is not None:
sql_statement = '''ALTER SEQUENCE %s_id_seq RESTART %s''' % (
cls._table_name, max_id+1)
cur.execute(sql_statement)
conn.commit()
cur.close()