Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python sqlite3选择更新的行值_Python_Python 2.7_Sqlite - Fatal编程技术网

python sqlite3选择更新的行值

python 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

我想打印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()

您需要执行两个查询(可能会减慢您的过程)。一个用于选择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