(20241129) Commit option added in SQL v2 file.

This commit is contained in:
2024-11-29 13:20:23 +05:30
parent 9c5c054bda
commit e52de710a1
+11 -1
View File
@@ -191,12 +191,18 @@ class AsyncMySQL:
# Done here: # Done here:
return all_result_sets 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. To call stored procedures and retrieve all the responses.
:param procedure_name: The name of the stored procedure that must be called. :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 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. :return: The raw result set as received from the database.
""" """
@@ -212,6 +218,7 @@ class AsyncMySQL:
async with connection.cursor() as cursor: async with connection.cursor() as cursor:
await cursor.callproc(procedure_name, procedure_args) await cursor.callproc(procedure_name, procedure_args)
all_result_sets = await self.fetch_all(cursor) all_result_sets = await self.fetch_all(cursor)
if commit: await connection.commit()
# # Iterate over all result sets, # # Iterate over all result sets,
# # and process them one-by-one: # # and process them one-by-one:
@@ -231,6 +238,7 @@ class AsyncMySQL:
self, self,
procedure_name, procedure_name,
procedure_args, procedure_args,
commit: bool = True,
retry_count = 1, retry_count = 1,
backoff_seconds = 0.5, backoff_seconds = 0.5,
backoff_multiplier = 1.1, 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). 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_name: The name of the stored procedure that must be called.
:param procedure_args: The args to be sent to the stored procedure. :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 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_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. :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( try: results = await self.call_procedure(
procedure_name = procedure_name, procedure_name = procedure_name,
procedure_args = procedure_args, procedure_args = procedure_args,
commit = commit
) )
except Exception as exc: exception = exc except Exception as exc: exception = exc
if exception is None: break if exception is None: break