-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload_data.py
More file actions
51 lines (38 loc) · 1.35 KB
/
Copy pathload_data.py
File metadata and controls
51 lines (38 loc) · 1.35 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import sqlite3
import os
def create_database():
# Delete the database file if it exists
if os.path.exists('donations.db'):
os.remove('donations.db')
# Connect to database
conn = sqlite3.connect('donations.db')
try:
# Read SQL file
with open('donation_schema.sql', 'r') as sql_file:
sql_script = sql_file.read()
# Execute SQL script
conn.executescript(sql_script)
print("Database created successfully!")
# Read SQL file
with open('donation_insert.sql', 'r') as sql_file:
sql_script = sql_file.read()
# Execute SQL script
conn.executescript(sql_script)
print("Database populated successfully!")
# Test the database
cursor = conn.cursor()
print("\nTesting views...")
print("\nDonor Summary:")
cursor.execute("SELECT * FROM donor_summary")
for row in cursor.fetchall():
print(row)
print("\nCampaign Summary:")
cursor.execute("SELECT * FROM campaign_summary")
for row in cursor.fetchall():
print(row)
except sqlite3.Error as e:
print(f"An error occurred: {e}")
finally:
conn.close()
if __name__ == "__main__":
create_database()