mbu-dev-shared-components 0.0.38__tar.gz → 0.0.40__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mbu_dev_shared_components-0.0.38/mbu_dev_shared_components.egg-info → mbu_dev_shared_components-0.0.40}/PKG-INFO +1 -1
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/utils/db_stored_procedure_executor.py +28 -3
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40/mbu_dev_shared_components.egg-info}/PKG-INFO +1 -1
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/.gitignore +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/LICENSE +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/README.md +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/getorganized/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/getorganized/auth.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/getorganized/cases.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/getorganized/contacts.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/getorganized/documents.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/getorganized/objects.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/google/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/google/api/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/google/api/auth.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/google/workspace/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/google/workspace/alerts.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/office365/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/office365/excel/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/office365/excel/excel_reader.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/office365/sharepoint_api/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/office365/sharepoint_api/files.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/os2forms/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/os2forms/documents.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/sap/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/sap/create_invoice.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/utils/__init__.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components/utils/json_handler.py +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components.egg-info/SOURCES.txt +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components.egg-info/requires.txt +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/mbu_dev_shared_components.egg-info/top_level.txt +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/pyproject.toml +0 -0
- {mbu_dev_shared_components-0.0.38 → mbu_dev_shared_components-0.0.40}/setup.cfg +0 -0
|
@@ -3,9 +3,9 @@ This module contains a generic function for executing stored procedures in a dat
|
|
|
3
3
|
via the pyodbc library. The function connects to the database and executes the stored
|
|
4
4
|
procedure with provided parameters, returning the success status and any error messages.
|
|
5
5
|
"""
|
|
6
|
-
import pyodbc
|
|
7
6
|
from typing import Dict, Any, Union
|
|
8
|
-
|
|
7
|
+
from dateutil import parser
|
|
8
|
+
import pyodbc
|
|
9
9
|
|
|
10
10
|
def execute_stored_procedure(connection_string: str, stored_procedure: str, params: Dict[str, Any]) -> Dict[str, Union[bool, str, Any]]:
|
|
11
11
|
"""
|
|
@@ -15,6 +15,7 @@ def execute_stored_procedure(connection_string: str, stored_procedure: str, para
|
|
|
15
15
|
connection_string (str): The connection string to connect to the database.
|
|
16
16
|
stored_procedure (str): The name of the stored procedure to execute.
|
|
17
17
|
params (Dict[str, Any]): A dictionary of parameters to pass to the stored procedure.
|
|
18
|
+
Each value should be a tuple of (type, actual_value).
|
|
18
19
|
|
|
19
20
|
Returns:
|
|
20
21
|
Dict[str, Union[bool, str, Any]]: A dictionary containing the success status, an error message (if any),
|
|
@@ -24,16 +25,40 @@ def execute_stored_procedure(connection_string: str, stored_procedure: str, para
|
|
|
24
25
|
"success": False,
|
|
25
26
|
"error_message": None,
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
type_mapping = {
|
|
30
|
+
"str": str,
|
|
31
|
+
"int": int,
|
|
32
|
+
"float": float,
|
|
33
|
+
"datetime": lambda x: parser.isoparse(x),
|
|
34
|
+
# Add more types if needed
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
try:
|
|
28
38
|
with pyodbc.connect(connection_string) as conn:
|
|
29
39
|
with conn.cursor() as cursor:
|
|
30
40
|
param_placeholders = ', '.join([f"@{key} = ?" for key in params.keys()])
|
|
41
|
+
param_values = []
|
|
42
|
+
|
|
43
|
+
for key, value in params.items():
|
|
44
|
+
if isinstance(value, tuple) and len(value) == 2:
|
|
45
|
+
value_type, actual_value = value
|
|
46
|
+
if value_type in type_mapping:
|
|
47
|
+
param_values.append(type_mapping[value_type](actual_value))
|
|
48
|
+
else:
|
|
49
|
+
param_values.append(actual_value)
|
|
50
|
+
else:
|
|
51
|
+
raise ValueError("Each parameter value must be a tuple of (type, actual_value).")
|
|
52
|
+
|
|
31
53
|
sql = f"EXEC {stored_procedure} {param_placeholders}"
|
|
32
|
-
cursor.execute(sql, tuple(
|
|
54
|
+
cursor.execute(sql, tuple(param_values))
|
|
33
55
|
conn.commit()
|
|
34
56
|
result["success"] = True
|
|
35
57
|
except pyodbc.Error as e:
|
|
36
58
|
result["error_message"] = f"Database error: {str(e)}"
|
|
59
|
+
except ValueError as e:
|
|
60
|
+
result["error_message"] = f"Value error: {str(e)}"
|
|
37
61
|
except Exception as e:
|
|
38
62
|
result["error_message"] = f"An unexpected error occurred: {str(e)}"
|
|
63
|
+
|
|
39
64
|
return result
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|