sql - Insert or replace not replacing in some cases with python sqlite3 -


i writing script scans through bunch of news articles , stores in sqlite database of individual words , how many times each word appears. in order using insert or replace described in this question. problem i'm having doesn't replace when should. think causing since sql queries happen in parallel, 1 word being inserted database , time script finds next appearance of same word, hasn't finished inserting database makes new entry (i.e. inserts instead of replaces). valid concern? if so, how make script wait until previous sql query has finished before executing next one?

here code inserting/replacing:

def incremement_or_insert(subject, word):     db = connect_to_db()     c = db.cursor()     query = "insert or replace subject_words (subject, word, count) values (?, ?, coalesce((select count + 1 subject_words subject = ? , word = ?), 1));"     c.execute(query, (subject, word, subject, word))     db.commit()     db.close 


Popular posts from this blog