Fixing SQLite Database is Locked Error when using jupyter notebook
初学sql,使用jupyter notebook写入门的SQL语句修改sqlite下的database文档,调试以下代码时:
path = '../code3/mbox-short.txt'
db = 'sql1.db'
fh = open(path)
conn = sqlite3.connect(db)
cur = conn.cursor()
for line in fh:
if not line.startswith('From: '): continue
pieces = line.split()
email = pieces[1]
cur.execute('SELECT count FROM Counts WHERE email = ?', (email,))#read the record
#? to avoid sql injection;#','make it a one item tuple
row = cur.fetchone()#the information we get from the database, if not in, row will be none
if row is None:
cur.execute('INSERT INTO Counts (email, count) VALUES (?,1)', (email,))
else:
cur.execute('UPDATE Counts SET count = count + 1 WHERE email = ?', (email,))#update is better
conn.commit() #note! if don't commit(), the db file will be empty
# read the selected data and print
sqlstr = 'SELECT email, count FROM

在使用jupyter notebook进行SQL学习时遇到'SQLite Database is Locked Error',问题源于即使关闭游标(cur.close()),数据库仍可能在后台打开,导致无法编辑。解决方法是重启kernel并重新运行所有代码。
1万+

被折叠的 条评论
为什么被折叠?



