如何检查 python sqlite3 中是否存在记录并在 tkinter 中引发错误?

How to check if record is exist in python sqlite3 and raise error in tkinter?

嗨,我是 sql 的新手,我正在尝试使用 sqlite3 数据库后端制作一个 tkinter 应用程序。我想将数据插入 sqlite 数据库,如果记录存在,它会在 tkinter 应用程序中引发错误。

只需进行 SQL 查询以查看该记录是否已存在。

如果是,则显示一个包含错误消息的消息框。

可以通过

检查记录是否存在
SELECT EXISTS(SELECT 1 FROM table_name WHERE some_column="some_value");

然后在你的代码中,你可以做

import tkinter.messagesbox as msgb
if exists:  # exists value comes from executing the query above
    msgb.showerror('Record already exists', 'Looks like the record alreadye xists')
else:
    # continue to inset the record
    pass