Skip to content

Commit e0a1de3

Browse files
committed
INTEGRITY: Parametrise sql queries in all files.
1 parent 70e5e92 commit e0a1de3

File tree

3 files changed

+157
-76
lines changed

3 files changed

+157
-76
lines changed

clear.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,30 @@
77
import json
88
import os
99

10+
1011
def truncate_all_tables(conn):
12+
# fmt: off
1113
tables = ["filechecksum", "queue", "history", "transactions", "file", "fileset", "game", "engine", "log"]
1214
cursor = conn.cursor()
13-
15+
# fmt: on
16+
1417
# Disable foreign key checks
1518
cursor.execute("SET FOREIGN_KEY_CHECKS = 0")
16-
19+
1720
for table in tables:
1821
try:
19-
cursor.execute(f"TRUNCATE TABLE `{table}`")
22+
cursor.execute("TRUNCATE TABLE %s", (table,))
2023
print(f"Table '{table}' truncated successfully")
2124
except pymysql.Error as err:
2225
print(f"Error truncating table '{table}': {err}")
23-
26+
2427
# Enable foreign key checks
2528
cursor.execute("SET FOREIGN_KEY_CHECKS = 1")
2629

30+
2731
if __name__ == "__main__":
2832
base_dir = os.path.dirname(os.path.abspath(__file__))
29-
config_path = os.path.join(base_dir, 'mysql_config.json')
33+
config_path = os.path.join(base_dir, "mysql_config.json")
3034
with open(config_path) as f:
3135
mysql_cred = json.load(f)
3236

@@ -41,9 +45,9 @@ def truncate_all_tables(conn):
4145
user=username,
4246
password=password,
4347
db=dbname, # Specify the database to use
44-
charset='utf8mb4',
48+
charset="utf8mb4",
4549
cursorclass=pymysql.cursors.DictCursor,
46-
autocommit=True
50+
autocommit=True,
4751
)
4852

4953
# Check connection
@@ -55,4 +59,4 @@ def truncate_all_tables(conn):
5559
truncate_all_tables(conn)
5660

5761
# Close connection
58-
conn.close()
62+
conn.close()

0 commit comments

Comments
 (0)