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
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 238 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Problem updating value in MySQL database dangermaus33 1 367 Nov-24-2020, 08:32 PM
Last Post: dangermaus33
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 413 Nov-08-2020, 06:54 AM
Last Post: isolatedastronaut
  capture print statement written in Stored Procedure in SQL Server brijeshkumar_77 0 959 Feb-18-2020, 03:22 AM
Last Post: brijeshkumar_77
  Execute SQL Server Stored Procedure brijeshkumar_77 0 1,220 Feb-18-2020, 02:59 AM
Last Post: brijeshkumar_77
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 1,226 Dec-26-2019, 05:57 AM
Last Post: buran
  What do you think of this procedure to create a path to a folder atlass218 10 2,675 Sep-06-2019, 07:53 AM
Last Post: atlass218
  Custom Function to Return Database Values rm78 0 722 Sep-05-2019, 01:01 PM
Last Post: rm78
  Add a stored procedure with variable using MySQL Connector UtiliseIT 0 1,097 May-04-2019, 12:46 PM
Last Post: UtiliseIT
  Unable to use sqlanydb to execute Sybase IQ Stored Procedure FORTITUDE 4 1,811 Sep-15-2018, 05:03 PM
Last Post: FORTITUDE

Forum Jump:

User Panel Messages

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