Q.Explain what the following query will do?
import mysql.connector db = mysql.connectar.connect(….) cursor = db.cursor() db.execute("SELECT * FROM staff WHERE person_id in {}".format((1,3,4))) db.commit() db.close()
Answer =
This above program give us error because above Mysql
query ( SELECT * FROM staff WHERE person_id in (1,3,4) ) do not affect any rows
so when db.commit() run then it show
error “Unread result found”.
Can you please elaborate a bit more? Is it because that formatting cant be used in select statements? And why don't it affect any rows?
ReplyDelete.commit() in MySQL Connector is used to send all changes in the cursor's batch to the MySQL server for permanent storage. It is necessary when you have executed an operation that affects the database schema or data, such as creating or modifying a table or inserting new records. This ensures that the changes are properly rolled back if an error occurs in the next transaction or if the user chooses to roll back the entire transaction. However, if you execute a simple SELECT statement or any other operation that does not modify the database, it is not necessary to use .commit().
Delete.commit() in MySQL Connector is used to send all changes in the cursor's batch to the MySQL server for permanent storage. It is necessary when you have executed an operation that affects the database schema or data, such as creating or modifying a table or inserting new records. This ensures that the changes are properly rolled back if an error occurs in the next transaction or if the user chooses to roll back the entire transaction. However, if you execute a simple SELECT statement or any other operation that does not modify the database, it is not necessary to use .commit().
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )