如何从 Python 中的 SQLite 查询中获取(扩展的)结果/错误代码?例如:
con = sqlite3.connect("mydb.sqlite")
cur = con.cursor()
sql_query = "INSERT INTO user VALUES(?, ?)"
sql_data = ("John", "MacDonald")
try:
cur.execute(sql_query, sql)
self.con.commit()
except sqlite3.Error as er:
# get the extended result code here
现在假设第一列应该是唯一的,并且第一列中已经有一个带有“John”的数据库条目。这将引发 IntegrityError,但我想知道 http://www.sqlite.org/rescode.html#extrc 上所述的 SQLite 结果/错误代码。我想知道,因为我想针对不同的错误采取不同的操作。
原文由 andere 发布,翻译遵循 CC BY-SA 4.0 许可协议
有关相关错误的更多信息可以通过以下方式获取: