问题
I'm having trouble accessing an out parameters values from a stored procedure in MySQL(8x) using Python(3.7) and sql connector (8x).
My stored procedure is an update procedure and it is working, however I don't know how to get the out value in code.
Here is my stored procedure...I simply want to access the out parameter named success in python.
CREATE DEFINER=`root`@`localhost` PROCEDURE `update_due_date`(param_bookId int, param_cardNumber int, param_dueDate date, out success int)
BEGIN
UPDATE tbl_book_loans
SET dueDate = param_dueDate
WHERE bookId = param_bookId and cardNo = param_cardNumber;
SET success = 777666;
END
Here is my python function (python 3.7), I just don't know what method to call on the cursor object, or how to approach this. The for loop also doesn't print anything, I'm assuming because the cursor stored results are empty.
Any help is appreciated, thanks.
def updateDueDate(bookId, cardNo, newDueDate):
args = [bookId, cardNo, newDueDate, 0]
myCursor.callproc(
'update_due_date', args)
myCursor.execute()
for result in myCursor.stored_results():
print(result.fetchall())
cnx.commit()
回答1:
This will get you the fourth parameter
See official documentation
def updateDueDate(bookId, cardNo, newDueDate):
args = [bookId, cardNo, newDueDate, 0]
result_args = cursor.callproc('update_due_date', args)
print(result_args[4])
来源:https://stackoverflow.com/questions/61977627/how-do-i-retrieve-an-out-parameter-from-a-mysql-stored-procedure-in-python-using