Python Forum
How to return value from a stored procedure of a MySQL database?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to return value from a stored procedure of a MySQL database?
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to capture the result set from a stored procedure? dee 5 5,077 May-25-2024, 01:03 AM
Last Post: deanhystad
  python script is hanging while calling a procedure in database prasanthi417 4 2,278 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  Mysql and mysql.connector error lostintime 2 1,839 Oct-03-2023, 10:25 PM
Last Post: lostintime
  python call stored procedure mg24 2 2,261 Oct-18-2022, 02:19 AM
Last Post: mg24
  python call stored procedure with two parameter mg24 4 5,089 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  Mysql error message: Lost connection to MySQL server during query tomtom 6 22,200 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  mySQL Database error not resolving. cybertooth 2 4,680 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 3,157 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Problem updating value in MySQL database dangermaus33 1 2,288 Nov-24-2020, 08:32 PM
Last Post: dangermaus33
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 2,112 Nov-08-2020, 06:54 AM
Last Post: isolatedastronaut

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020