Python Forum

Full Version: How to return value from a stored procedure of a MySQL database?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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