python sqlite3选择更新的行值
我想打印SQL查询中更新行的行idpython sqlite3选择更新的行值,python,python-2.7,sqlite,Python,Python 2.7,Sqlite,我想打印SQL查询中更新行的行id while True: Conn = sqlite3.connect('database.db', timeout=60) c = Conn.cursor() c.execute("UPDATE row SET value='value' where status='status'") #i want to do something here to the updated row above Conn.commit() Conn.clo
while True:
Conn = sqlite3.connect('database.db', timeout=60)
c = Conn.cursor()
c.execute("UPDATE row SET value='value' where status='status'")
#i want to do something here to the updated row above
Conn.commit()
Conn.close()
您需要执行两个查询(可能会减慢您的过程)。一个用于选择ID,另一个用于更新相应的ID
while True:
connection = sqlite3.connect('database.db', timeout=60)
cursor = connection.cursor()
# Get IDs to update
rows = cursor.execute("SELECT id FROM row WHERE status='status'")
ids = [str(x) for x, in rows] # Transform tupple list to list of string
# Update corresponding IDs
cursor.execute(
"UPDATE row SET value='value' WHERE id in ({0})".format(','.join(ids)))
# Do what you want with `ids`...
connection.commit()
connection.close()
这将更新表中的所有行
行
。我认为您需要更清楚地了解您想要返回的内容(以及为什么while True
?!)while True是因为我希望它现在一直运行,但我真正想要的是得到该查询的结果并知道它影响了哪一行id