Home > Mobile >  Running more than one execute function in python give error 'Unread result found' , how to
Running more than one execute function in python give error 'Unread result found' , how to

Time:01-19

My Code

Second last line is showing error <Unread.result.found> but when i run it individually it run successfully

import mysql.connector as msqc
import numpy as np

db = msqc.connect(
    host="localhost",
    username="root",
    password=" ",
    database="hotel",
)
cur = db.cursor()

ss = 'SELECT one_bed ,Available_one_bed from rooms where Available_one_bed = "A" '
cur.execute(ss)
available_room = cur.fetchone()
print(available_room[0])
cur.execute('SELECT * from rooms')
s = 'UPDATE rooms SET Available_one_bed = "N/A" WHERE one_bed = ' str(100)
cur.execute(s)

CodePudding user response:

Most likely not all data where read after first execute. You need a buffered cursor, e.g.

cur = db.cursor(buffered=True)

some details could be found here https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursorbuffered.html

  •  Tags:  
  • Related