From c1063542050ca7f413b8f7ba13bcc1a8447ce204 Mon Sep 17 00:00:00 2001 From: Richard Tingstad Date: Sat, 5 Jan 2019 21:28:30 +0100 Subject: [PATCH] Fix word_id in 25-persistent-tables "MAX(id) FROM words" was used as word_id for INSERT of next word, which will result in duplicate word ids. (Of course, in its current form, the application always runs the code against an empty database, so the error is not triggered.) --- 26-persistent-tables/tf-26.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/26-persistent-tables/tf-26.py b/26-persistent-tables/tf-26.py index e7bd61e..59361ae 100755 --- a/26-persistent-tables/tf-26.py +++ b/26-persistent-tables/tf-26.py @@ -37,9 +37,7 @@ def _extract_words(path_to_file): # Add the words to the database c.execute("SELECT MAX(id) FROM words") row = c.fetchone() - word_id = row[0] - if word_id == None: - word_id = 0 + word_id = row[0] + 1 if row[0] != None else 0 for w in words: c.execute("INSERT INTO words VALUES (?, ?, ?)", (word_id, doc_id, w)) # Add the characters to the database