Stored procedures in Frappe

We want to call a stored procedure of Maria DB and want to execute it through the frappe framework code. I have tried frappe.db.sql(“CALL SPNAME;”) but it’s not working, has anyone tried it practically, pls share some sample code. it will be a great help.

1 Like

Hi,

Following code is generated by the ChatGPT, you may try:

from frappe.database import Database
from frappe import _

db = Database(user='root', password='password', host='localhost', port=3306)

db.connect()

try:
    db.sql("CALL my_stored_procedure()")
    db.commit()
    print(_("Stored Procedure executed successfully"))
except Exception as e:
    db.rollback()
    print(_("Error executing stored procedure: {0}").format(str(e)))
finally:
    db.close()

You can replace my_stored_procedure() with the name of your stored procedure. This code snippet uses the frappe.database module to connect to the MariaDB database and execute the stored procedure

Pls try this code, i tried it but not working

This code not working