-2

I need to call a MySQL stored procedure from Python, and I don't need to wait for the procedure to finish.

How can this be done?

user3663896
  • 9
  • 1
  • 3
  • Well what have you got so far? Do you know how to perform a task asynchronously? Do you know how to execute a stored procedure? or any SQL statement? Do you know how to connect to a database? – khelwood Jun 16 '19 at 22:38
  • Hi, I know how to create a stored procedure in MySQL, I know how to exetute a stored procedure from python, my programs use MySQL intensively, so I know how to connect to a database (MySQL, Postgress, SQL Server, Oracle, etc)... But my problem is to call a stored procedure and don't wait for it to finish. – user3663896 Jun 18 '19 at 07:29
  • It might help your question to add all that information to your question and include the code showing what you have already, so there is a context and not just a vague requirement. – khelwood Jun 18 '19 at 07:59

2 Answers2

0

One possible solution is by using celery: "Celery is an asynchronous task queue/job queue based on distributed message passing.". You can create a task where you call your MySQL store procedure.

Manuel Carrero
  • 599
  • 1
  • 9
  • 29
  • It's not the solution I'm looking for. I need my Python program to call a stored procedure and don't wait for it to finish – user3663896 Jun 18 '19 at 07:30
0

code below work for me

import mysql.connector

def insertComment(ecID, eID, eComment):
    try:
        contraseña = input("Please, enter your database password: ")
        connection = mysql.connector.connect(host='localhost',
                                             database='mantenimiento',
                                             user='hernan',
                                             password=contraseña,
                                             port=3309)
        if connection.is_connected():
            cursor = connection.cursor(prepared=True)
            procedure = "call mantenimiento.spSaveComment(%s, %s, %s)"
            datos = (ecID, eID, eComment)
            cursor.execute(procedure, datos)
            # datos = [(ecID, eID, eComment)]  # Tuple for executemany
            # cursor.executemany(procedure, datos)
            connection.commit()
            print(cursor.rowcount, "Comment inserted sucessfully")
    except mysql.connector.Error as error:
        connection.rollback()
        print("Failed to insert value into database {}".format(error))
    finally:
        if (connection.is_connected()):
            cursor.close()
            connection.close()
            print("Server connection was closed")


insertComment(15, 25, 'Test MariaDB or MySQL SP from python')