1

I am using mysql-connector-python 8.0.33 and tring to fetch all records from database using following code .

def retrieve_records():
    try:
        cursor = conn.cursor(buffered= True)
        cursor.execute(f"SELECT * FROM {scanner.table_name}")
        records = cursor.fetchall()
        tree.delete(*tree.get_children())

        for record in records:
            tree.insert("", "end", values=record)

        while cursor.nextset():
            pass  # Consume any remaining unread result sets

        cursor.close()
    except mysql.connector.Error as err:
        messagebox.showerror("Error", f"An error occurred while retrieving the records: {err}")

I am calling following function in a loop and there is an issue. Every time when I run the program and the loop is executed very first time I get Unread result found error every time. In short it goes to exception block in every first iteration.

enter image description here

Basically my program scan the qr code and store it to database and show the data in json decoded format on UI and here is one feature that if there is data in database already it should load it in list first. But not working it is giving error as mentioned above.

Traceback (most recent call last):
  File "C:\Users\Credencys\Desktop\qr\app.py", line 196, in <module>
    retrieve_records()
  File "C:\Users\Credencys\Desktop\qr\app.py", line 99, in retrieve_records
    cursor = conn.cursor()
             ^^^^^^^^^^^^^
  File "C:\Users\Credencys\AppData\Local\Programs\Python\Python311\Lib\site-packages\mysql\connector\connection_cext.py", line 676, in cursor       
    self.handle_unread_result(prepared)
  File "C:\Users\Credencys\AppData\Local\Programs\Python\Python311\Lib\site-packages\mysql\connector\connection_cext.py", line 932, in handle_unread_result
    raise InternalError("Unread result found")
mysql.connector.errors.InternalError: Unread result found

After removing try catch getting following trace and Open-cv is for that i am using this function in a program where open-cv is used.

4
  • Are you quite sure the error comes from this exact code? Because calling fetchall is by itself enough to turn off this error. nextset is unnecessary; you only have one SELECT here. Commented Jun 25, 2023 at 4:23
  • Why the OpenCV tag? Commented Jun 25, 2023 at 4:31
  • If you comment out the try and except, where does it fail? Is it on the execute or the close? Commented Jun 25, 2023 at 5:06
  • Your traceback doesn't have the buffered=True parameter. In any case, are you doing other database accesses before you run this one? And if your problem isn't related to OpenCV (which it isn't), then don't include the tag. Commented Jun 25, 2023 at 6:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.