如何基于ROWID删除数据



使用python,如何根据lastrowid删除数据。我已删除所有行的代码代码:

import re
import sys
import difflib
import sqlite3
def main():   
   while True:      
      name = input ('Please Type your Question:  ').lower().split()  
      name2 = name[:]
      import sqlite3
      for item in name2:#break                
         conn = sqlite3.connect("foods.db")
         cursor = conn.cursor()           
         cursor.execute("INSERT INTO INPUT33 (NAME) VALUES (?);", (name2,))      
         cursor.execute("select MAX(rowid) from [input33];")
         conn.commit()      
         for rowid in cursor:break         
         for elem in rowid:
            m = elem            
            print(m)
            cursor.execute("DELETE FROM INPUT33 (NAME) WHERE NAME = name")

要获取最后一个插入的rowID,请使用光标的lastrowid属性。

要删除具有特定rowID的记录,请在Where条件下使用该列:

cursor.execute("INSERT INTO input33(Name) VALUES(?)", ("whatever",))
rowid = cursor.lastrowid
cursor.execute("DELETE FROM input33 WHERE rowid = ?", (rowid,))

相关内容

  • 没有找到相关文章