Python Forum
How to return value from a stored procedure of a MySQL database? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to return value from a stored procedure of a MySQL database? (/thread-19968.html)



How to return value from a stored procedure of a MySQL database? - UtiliseIT - Jul-22-2019

Hi,

I am working with a MySQL database and am having trouble with the line(s) of code that returns values when using a stored procedure that will return a single value.

When using a select statement, the following works perfect
cursor.execute(query)
data = cursor.fetchall()
    
cursor.close()
cnx.close()

return {'statusCode': 200,
        'Content-Type': 'application/json'},
        "body": json.dumps(data)}
the following example works fine for my sp but i’ve never had to return a value from the sp
cursor.callproc('sp_h', args)
cnx.commit()

cursor.close()
cnx.close()

return {
    "statusCode": 200,
    "headers": {
        "Content-Type": "application/json"
    },
    "body": json.dumps({
        "message": "Combination(s) Successfully inserted"
		})
    }
What would I need to add to send back the single value into the body??

Thanks in advance

Todd