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
  python script is hanging while calling a procedure in database prasanthi417 4 442 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  Mysql and mysql.connector error lostintime 2 609 Oct-03-2023, 10:25 PM
Last Post: lostintime
  python call stored procedure mg24 2 1,029 Oct-18-2022, 02:19 AM
Last Post: mg24
  python call stored procedure with two parameter mg24 4 1,403 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,673 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  mySQL Database error not resolving. cybertooth 2 3,113 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,113 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Problem updating value in MySQL database dangermaus33 1 1,589 Nov-24-2020, 08:32 PM
Last Post: dangermaus33
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 1,540 Nov-08-2020, 06:54 AM
Last Post: isolatedastronaut
  capture print statement written in Stored Procedure in SQL Server brijeshkumar_77 0 2,515 Feb-18-2020, 03:22 AM
Last Post: brijeshkumar_77

Forum Jump:

User Panel Messages

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