Attender / dump_db_to_sql.py
chualinwei3's picture
Upload 30 files
f742815 verified
Raw
History Blame Contribute Delete
1.08 kB
import sqlite3
import os
def dump_sqlite_to_sql(db_path, output_path):
# Check if DB exists
if not os.path.exists(db_path):
print(f"Error: Database file '{db_path}' not found.")
return
try:
# Connect to the database
conn = sqlite3.connect(db_path)
# Open the output file
with open(output_path, 'w', encoding='utf-8') as f:
# Iterate through the dump and write to file
for line in conn.iterdump():
f.write('%s\n' % line)
print(f"Successfully dumped '{db_path}' to '{output_path}'.")
conn.close()
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
db_file = "attendr.db"
sql_file = "attendr.sql"
# Get absolute paths
current_dir = os.getcwd()
db_path = os.path.join(current_dir, db_file)
output_path = os.path.join(current_dir, sql_file)
print(f"Dumping {db_path}...")
dump_sqlite_to_sql(db_path, output_path)