-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbx.py
More file actions
22 lines (17 loc) · 678 Bytes
/
Copy pathdbx.py
File metadata and controls
22 lines (17 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sqlite3
def clear_tables(db_path, table_names, reset_autoincrement=True):
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
for table in table_names:
cursor.execute(f"DELETE FROM {table};")
print(f"Cleared table: {table}")
if reset_autoincrement:
cursor.execute("DELETE FROM sqlite_sequence WHERE name=?;", (table,))
print(f"Reset AUTOINCREMENT for: {table}")
conn.commit()
except sqlite3.Error as e:
print(f"SQLite error: {e}")
finally:
conn.close()
clear_tables("db.sqlite3", ["TamptoProject_sajili","TamptoProject_michango"])