简体   繁体   中英

Mariadb python: Commands out of syncs

so I was trying to create a password manager for myself, using python and mariadb. After creating a table named pw, which contains Name, Account and Passwords 3 columns, I tried to create a function(Search_Passwords(app_name)) which I can use to enter a keyword to search in the database, and it will give me the right passwords. However, I ran into this error message: Commands out of syncs error message.

I'm new to python and mariadb(using it cause for some reason MySQL doesn't work..), tried to look up for some answers but still can't figure it out. Can anyone help please? Below are other codes I think might be related.

This is what mariadb's table looks like.

Search_Passwords()

class UseDataBase

This is what I found online as a reference version where Search_Passwords() involved.

Sorry if my codes are not perfect... :(

MariaDB Connector/Python by default use unbuffered result sets, which means before executing another cursor all pending result sets need to be fetched or the cursor needs to be closed.

For example the following script

import mariadb

conn= mariadb.connect()
cursor1= conn.cursor()
cursor1.execute("select 1 from dual")
cursor2= conn.cursor()
cursor2.execute("select 2 from dual")

will throw an exception Mariadb.InterfaceError: Commands out of sync; you can't run this command now Mariadb.InterfaceError: Commands out of sync; you can't run this command now .

To avoid this, you need to create a buffered cursor:

cursor1= conn.cursor(buffered=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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