Код не может удалить строку в таблице mysql с указанным именем или именем продукта - PullRequest
0 голосов
/ 25 апреля 2020

Код, используемый для удаления выбранного элемента:

def deletecase(self):
    if not self.tree.selection():
        ms.showerror('ERROR!!', 'INVALID SELECTION')
    else:
        result = ms.askquestion('CONFIRMATION!!', 'Are you sure you want to delete this record%s', icon="warning")
        if result == 'yes':
            curItem = self.tree.focus()
            contents = (self.tree.item(curItem))
            selecteditem = (contents['values'])
            print(selecteditem)
            self.tree.delete(curItem)
            print(selecteditem[1])
            sql = "DELETE FROM Cases WHERE caseid = %s"
            adr = str(selecteditem[1])
            c.execute(sql, adr)

Это сообщение об ошибке:

Exception in Tkinter callback
[32, 'Big Case', 0, 'water', 320, 350, 50, 0]
Big Case
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s' at line 1

Процесс завершен с кодом выхода 0

1 Ответ

2 голосов
/ 25 апреля 2020

Попробуйте сделать аргумент кортежем вместо строки:

    ...
    sql = "DELETE FROM Cases WHERE caseid = %s"
    adr = str(selecteditem[1])
    c.execute(sql, (adr,))  # pass the argument as a tuple
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...