简体   繁体   English

Python sqlite3 update 删除我的行而不是更新值

[英]Python sqlite3 update deletes my row instead of updating the value

I am trying to update a value x based on a specified row ID y in python using sqlite3.我正在尝试使用 sqlite3 根据 python 中指定的行 ID y 更新值 x。 However, the issue I have is that instead of updating the value in the specified column, the script deletes the entire row/entry from the database.但是,我遇到的问题是,脚本没有更新指定列中的值,而是从数据库中删除整个行/条目。

Here is the function这是函数

def closeIssue(self, issue_id, resolver_discord_id):
        # This function closes an open issue and assigns the resolver's ID
        self.c.execute("SELECT * FROM issues WHERE issue_id={}".format(issue_id))
        result = self.c.fetchone()
        if not result:
            print("No such record")
        else:
            self.c.execute("UPDATE issues SET issue_status = 'CLOSED' where issue_id = ?", (issue_id))
            self.conn.commit()

        self.__closeDatabase(False)

Just for further context, here are below some other parts of the module.只是为了进一步了解,下面是模块的其他一些部分。

The database maker (and structure):数据库制造商(和结构):

def __buildDatabase(self):
        conn = sqlite3.connect(self.issue_db)
        c = conn.cursor()
        c.execute("""CREATE TABLE issues (
                        issue_id integer,
                        issue_type text,
                        issue_type_verbose text,
                        author_discord integer,
                        issue_content text,
                        issue_status text,
                        issue_creation_timestamp text,
                        issue_closed_timestamp text,
                        resolver_staff_discord integer
                        )""")
        conn.commit()
        print("Database created")

What a typical entry looks like:一个典型的条目是什么样的:

[{'issue_id': 1, 'issue_type': 'reports', 'issue_type_verbose': 'Report', 'author_discord': 124123123, 'issue_content': 'report one', 'issue_status': 'OPEN', 'issue_creation_timestamp': '14:29:33 - 20/02/2020', 'issue_closed_timestamp': 'NONE', 'resolver_staff_discord': 'NONE'}, {'issue_id': 2, 'issue_type': 'reports', 'issue_type_verbose': 'Report', 'author_discord': 41312, 'issue_content': 'report two', 'issue_status': 'OPEN', 'issue_creation_timestamp': '14:29:42 - 20/02/2020', 'issue_closed_timestamp': 'NONE', 'resolver_staff_discord': 'NONE'}]

I hope you can help me with this, thank you in advance!我希望你能帮我解决这个问题,先谢谢你! I've been hitting my head on this issue for the last few hours and cannot seem to find a solution anywhere I look.在过去的几个小时里,我一直在思考这个问题,但似乎在任何地方都找不到解决方案。

I fixed it.我修好了它。 I am stupid.我很蠢。 Apologies in advance and I guess I deserve it for the last three hours.提前道歉,我想在过去的三个小时里我应得的。 Turns out the issue was in the way I displayed my test output... it was filtered out for only open cases.原来问题出在我显示测试输出的方式上......它只被过滤掉了打开的案例。 Jesus.耶稣。 Alright so confirmed this code works as intended.好的,因此确认此代码按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM