Skip to content

Commit 390d4d5

Browse files
committed
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.)
1 parent ed8c3ca commit 390d4d5

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

25-persistent-tables/tf-25.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def _extract_words(path_to_file):
3737
# Add the words to the database
3838
c.execute("SELECT MAX(id) FROM words")
3939
row = c.fetchone()
40-
word_id = row[0]
41-
if word_id == None:
42-
word_id = 0
40+
word_id = row[0] + 1 if row[0] != None else 0
4341
for w in words:
4442
c.execute("INSERT INTO words VALUES (?, ?, ?)", (word_id, doc_id, w))
4543
# Add the characters to the database

0 commit comments

Comments
 (0)