Skip to content

Commit

Permalink
Handle an empty changes_nextid table
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris AtLee committed Apr 1, 2010
1 parent 0b112c2 commit bad8208
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion buildbot/db/connector.py
Expand Up @@ -311,12 +311,19 @@ def addChangeToDatabase(self, change):
def _txn_addChangeToDatabase(self, t, change):
t.execute("SELECT next_changeid FROM changes_nextid")
r = t.fetchall()
new_next_changeid = old_next_changeid = r[0][0]
if not r:
new_next_changeid = old_next_changeid = 1
q = "INSERT INTO changes_nextid (next_changeid) VALUES (?)"
t.execute(self.quoteq(q), (old_next_changeid,))
else:
new_next_changeid = old_next_changeid = r[0][0]

if change.number is None:
change.number = old_next_changeid
new_next_changeid = old_next_changeid + 1
else:
new_next_changeid = max(old_next_changeid, change.number+1)

if new_next_changeid > old_next_changeid:
q = "UPDATE changes_nextid SET next_changeid = ? WHERE 1"
t.execute(self.quoteq(q), (new_next_changeid,))
Expand Down

0 comments on commit bad8208

Please sign in to comment.