@@ -9,7 +9,7 @@ def get_tombll_json(path):
99 """Load and parse a JSON file from a specified path.
1010
1111 Attempts to open and read a JSON file, parsing its content into a dictionary.
12- Handles errors for file not found, JSON decoding issues, and other I/O problems.
12+ Exit on errors for file not found, JSON decoding issues, and other I/O problems.
1313
1414 Args:
1515 path (str): The path to the JSON file.
@@ -52,7 +52,7 @@ def query_return_everything(query, params, con):
5252
5353 Args:
5454 query (str): The SQL query to execute. Expected to be a SELECT or similar.
55- params (tuple): A tuple of parameters to safely bind to the query.
55+ params (tuple or None ): A tuple of parameters to safely bind to the query.
5656 con (sqlite3.Connection): An open SQLite database connection.
5757
5858 Returns:
@@ -92,9 +92,12 @@ def query_return_id(query, params, con):
9292 For other queries, it fetches and returns the first integer result, if it exists and is
9393 non-negative.
9494
95+ If a database error occurs, the error is logged, any open transaction is rolled back,
96+ and the program exits with an error status.
97+
9598 Args:
9699 query (str): SQL query to execute.
97- params (tuple): Parameters for the query.
100+ params (tuple or None ): Parameters for the query.
98101 con (sqlite3.Connection): SQLite database connection.
99102
100103 Returns:
@@ -105,8 +108,12 @@ def query_return_id(query, params, con):
105108 """
106109 cursor = con .cursor ()
107110 try :
108- # Execute the query with provided parameters
109- cursor .execute (query , params )
111+ if params :
112+ # Execute the query with the given parameters
113+ cursor .execute (query , params )
114+ else :
115+ # Execute the query without parameters
116+ cursor .execute (query )
110117
111118 # Check if it's an INSERT query to return the last inserted row ID
112119 if query .strip ().upper ().startswith ("INSERT" ):
@@ -129,18 +136,26 @@ def query_return_id(query, params, con):
129136def query_run (query , params , con ):
130137 """Execute a SQL query with the provided parameters.
131138
139+ If a database error occurs, the error is logged, any open transaction is rolled back,
140+ and the program exits with an error status.
141+
132142 Args:
133143 query (str): The SQL query to execute.
134- params (tuple): Parameters to substitute in the SQL query.
144+ params (tuple or None ): Parameters to substitute in the SQL query.
135145 con (sqlite3.Connection): SQLite database connection.
136146
137147 Exits:
138148 Logs an error and exits if a database error occurs.
139149 """
140150 cursor = con .cursor ()
141151 try :
142- # Execute the query with provided parameters
143- cursor .execute (query , params )
152+ if params :
153+ # Execute the query with the given parameters
154+ cursor .execute (query , params )
155+ else :
156+ # Execute the query without parameters
157+ cursor .execute (query )
158+
144159 except sqlite3 .DatabaseError as db_error :
145160 # Log the database error and exit the program
146161 logging .error ("Database error occurred: %s" , db_error )
@@ -157,6 +172,6 @@ def make_empty_null(value):
157172 Returns:
158173 None if the value is an empty string or exactly 0.0; otherwise, returns the original value.
159174 """
160- if value in ("" , 0.0 ):
175+ if value in ("" , 0.0 , 0 ):
161176 return None
162177 return value
0 commit comments