From e52de710a1786531f7826fd8aab34dc18eabe44a Mon Sep 17 00:00:00 2001 From: khushal Date: Fri, 29 Nov 2024 13:20:23 +0530 Subject: [PATCH] (20241129) Commit option added in SQL v2 file. --- utils_v2/database/async_mysql_v2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utils_v2/database/async_mysql_v2.py b/utils_v2/database/async_mysql_v2.py index f4cac6e..6a1996f 100644 --- a/utils_v2/database/async_mysql_v2.py +++ b/utils_v2/database/async_mysql_v2.py @@ -191,12 +191,18 @@ class AsyncMySQL: # Done here: return all_result_sets - async def call_procedure(self, procedure_name, procedure_args): + async def call_procedure( + self, + procedure_name: str, + procedure_args: tuple, + commit: bool = True + ): """ To call stored procedures and retrieve all the responses. :param procedure_name: The name of the stored procedure that must be called. :param procedure_args: The args to be sent to the stored procedure. + :param commit: Whether, or not, you would like to commit the execution. :return: The raw result set as received from the database. """ @@ -212,6 +218,7 @@ class AsyncMySQL: async with connection.cursor() as cursor: await cursor.callproc(procedure_name, procedure_args) all_result_sets = await self.fetch_all(cursor) + if commit: await connection.commit() # # Iterate over all result sets, # # and process them one-by-one: @@ -231,6 +238,7 @@ class AsyncMySQL: self, procedure_name, procedure_args, + commit: bool = True, retry_count = 1, backoff_seconds = 0.5, backoff_multiplier = 1.1, @@ -242,6 +250,7 @@ class AsyncMySQL: This is custom formatting based on the structure created by Mr. bhushan Thakkar in late April (2024). :param procedure_name: The name of the stored procedure that must be called. :param procedure_args: The args to be sent to the stored procedure. + :param commit: Whether, or not, you would like to commit the execution. :param retry_count: The max. number of times to try in case one or more attempts fail. :param backoff_seconds: The time to wait before making the next attempt if the retry count is more than 1. :param backoff_multiplier: The factor that dictates how much to modify the time delay by when waiting to retry. @@ -259,6 +268,7 @@ class AsyncMySQL: try: results = await self.call_procedure( procedure_name = procedure_name, procedure_args = procedure_args, + commit = commit ) except Exception as exc: exception = exc if exception is None: break