0

I am executing the following sql statement from python program on Mysql database.

    mydb = mysql.connector.connect(
        host="localhost",
        user="root",
        passwd="",
        database="fmysql",
    )
    mycursor = mydb.cursor()

   sql = "SELECT f_name FROM STUDENTS where ID_No =   %s " % self.leID_no.text()
   mycursor.execute(sql)

where self.ID_no.text()is a QLineEdut field in pyqt5 form. this code is showing an error when the leID_no text is an Arabic number digits e.i. (١٢٣),the error message is:

mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column '١٢٣' in 'where clause'

but when leID_no text is an english number digits (0-9), the query run with no errors!

I am using the following setup: mac, python3.8, pyqt5, Mysql, charset (utf8, utf8_unicode_ci)

any help to solve this problem?

Fawaz
  • 83
  • 1
  • 6
  • What's the type of column ID_No – Agung Wiyono Jun 26 '20 at 02:46
  • You need to enclose the value in quotes if it is not numeric: `sql = "SELECT f_name FROM STUDENTS where ID_No = '%s' " % self.leID_no.text()` – Nick Jun 26 '20 at 02:48
  • 1
    Rather than using string formatting, pass the values to `cursor.execute` like in this example https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-select.html – snakecharmerb Jun 26 '20 at 07:15
  • 1
    Be aware that "١٢٣" and "123" (or "321") are not equal in any syntax of MySQL. – Rick James Jun 26 '20 at 17:05

0 Answers0