V
V
venera0602020-12-22 20:23:24
MySQL
venera060, 2020-12-22 20:23:24

Mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column ' ' in 'where clause'. How to decide?

the function accepts an incoming message:

def check_answer(message):

    db_work = mySQL()

    a = db_work.check_answers(message)
    print(a)
    db_work.close()


send a query to the database if the table has the following value:
def check_answers(self, text):
        self.cursor.execute("SELECT * FROM answers WHERE text = " + str(text))
        data = self.cursor.fetchone()
        return data


it responds normally to the first 2 numeric requests. on the third aggro.
you need to make foolproof:
if the user drives in something random, and not the values ​​\u200b\u200bthat are in the database,
data should simply return 0, None, False. (whatever)
But it crashes and writes that the column was not found when it is not a column but a value in the column

5fe22a37b4d3d806811379.png
5fe22a19d3790646695870.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2020-12-22
@venera060

fix it

self.cursor.execute("SELECT * FROM answers WHERE text = " + str(text))

on the
self.cursor.execute("SELECT * FROM answers WHERE text = '" + str(text) + "'")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question