我是sqlite的新手。
我使用python创建了一个带有营养素表的sqlite数据库(请参阅屏幕快照中的结构)。
我已经使用
填充了表格INSERT INTO nutrients ...
但是,我似乎无法更新一行。以下代码
import sqlite3
path = 'nutrition.sqlite'
command = 'SELECT user_name FROM nutrients WHERE code="ALCO"'
connection = sqlite3.connect(path)
cursor = connection.cursor()
cursor.execute(command)
rows = cursor.fetchall()
cursor.close()
connection.close()
print('before update', rows[0])
command = 'UPDATE nutrients SET user_name="Booze" WHERE code="ALCO"'
connection = sqlite3.connect(path)
cursor = connection.cursor()
cursor.execute(command)
cursor.close()
connection.close()
command = 'SELECT user_name FROM nutrients WHERE code="ALCO"'
connection = sqlite3.connect(path)
cursor = connection.cursor()
cursor.execute(command)
rows = cursor.fetchall()
cursor.close()
connection.close()
print('after update', rows[0])
产生输出
('before update', (u'Alcohol',))
('after update', (u'Alcohol',))