File size: 1,078 Bytes
f742815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

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)