tdfs4ds 0.2.4.25__py3-none-any.whl → 0.2.4.41__py3-none-any.whl

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.
@@ -84,71 +84,49 @@ def execute_query_wrapper(f):
84
84
  return wrapped_f
85
85
 
86
86
 
87
- def execute_query(query):
87
+ def execute_query(query, raise_error=False):
88
88
  """
89
89
  Execute a SQL query or a list of queries using the tdml module.
90
90
 
91
- This function checks the version of the tdml module and executes the query or queries accordingly.
92
- For versions greater than 17.20.00.03, it uses `tdml.execute_sql`; otherwise, it uses `tdml.get_context().execute`.
93
-
94
91
  Args:
95
92
  query (str or list): A single SQL query string or a list of SQL query strings.
93
+ raise_error (bool): If True, re-raise exceptions after printing them. Default is False.
96
94
 
97
95
  Returns:
98
96
  The result of the SQL execution if a single query is passed. None if a list of queries is passed or an exception occurs.
97
+ """
98
+ def handle_exception(e, q):
99
+ # Always print error
100
+ print(str(e).split('\n')[0])
101
+ print(q)
99
102
 
100
- Example:
101
- To execute a single SQL query and retrieve the result:
102
- >>> result = execute_query("SELECT * FROM my_table")
103
-
104
- To execute a list of SQL queries:
105
- >>> execute_query(["UPDATE table1 SET column1 = 42", "DELETE FROM table2 WHERE condition"])
106
-
107
- Note:
108
- - If a single query is passed, the function returns the result of the SQL execution.
109
- - If a list of queries is passed, the function executes each query and returns None.
110
- - If an exception occurs during execution, the error message and the problematic query are printed,
111
- and the function returns None.
103
+ # Raise exception only if requested
104
+ if raise_error:
105
+ raise e
112
106
 
113
- """
114
- # Check if the version of tdml is greater than the specified base version
115
107
  if is_version_greater_than(tdml.__version__, base_version="17.20.00.03"):
116
- # If query is a list, iterate and execute each query
117
- if type(query) == list:
108
+ if isinstance(query, list):
118
109
  for q in query:
119
110
  try:
120
- tdml.execute_sql(q) # Execute the query
111
+ tdml.execute_sql(q)
121
112
  except Exception as e:
122
- # Print the first line of the exception and the query that caused it
123
- print(str(e).split('\n')[0])
124
- print(q)
113
+ handle_exception(e, q)
125
114
  else:
126
- # If query is not a list, execute it and return the result
127
115
  try:
128
116
  return tdml.execute_sql(query)
129
117
  except Exception as e:
130
- # Print the first line of the exception and the query
131
- print(str(e).split('\n')[0])
132
- print(query)
118
+ handle_exception(e, query)
133
119
  else:
134
- # For tdml versions not greater than the specified version
135
- if type(query) == list:
120
+ if isinstance(query, list):
136
121
  for q in query:
137
122
  try:
138
- # Use the older execution method for the query
139
123
  tdml.get_context().execute(q)
140
124
  except Exception as e:
141
- # Print the first line of the exception and the query
142
- print(str(e).split('\n')[0])
143
- print(q)
125
+ handle_exception(e, q)
144
126
  else:
145
127
  try:
146
- # Execute the single query using the older method and return the result
147
128
  return tdml.get_context().execute(query)
148
129
  except Exception as e:
149
- # Print the first line of the exception and the query
150
- print(str(e).split('\n')[0])
151
- print(query)
130
+ handle_exception(e, query)
152
131
 
153
- # No return value if a list of queries is executed or if an exception occurs
154
- return
132
+ return None