我想打印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.close()
答案 0 :(得分:0)
您需要执行两次查询(可能会降低您的流程速度)。一个用于选择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()