File size: 1,221 Bytes
345a446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Run this once to create the default sample database.
Usage: python create_db.py
"""
import sqlite3
import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DB_FOLDER = os.path.join(BASE_DIR, "database")
DB_PATH = os.path.join(DB_FOLDER, "company.db")

os.makedirs(DB_FOLDER, exist_ok=True)

conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()

cursor.execute("""
CREATE TABLE IF NOT EXISTS customers(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    age INTEGER,
    city TEXT,
    email TEXT
)
""")

cursor.execute("SELECT COUNT(*) FROM customers")
count = cursor.fetchone()[0]

if count == 0:
    customers = [
        ("Ali", 23, "Lahore", "ali@gmail.com"),
        ("Ahmed", 25, "Islamabad", "ahmed@gmail.com"),
        ("Sara", 22, "Karachi", "sara@gmail.com"),
        ("Usman", 27, "Lahore", "usman@gmail.com"),
        ("Ayesha", 24, "Faisalabad", "ayesha@gmail.com"),
    ]
    cursor.executemany(
        "INSERT INTO customers(name, age, city, email) VALUES (?, ?, ?, ?)",
        customers,
    )
    print("✅ Sample data inserted.")
else:
    print("ℹ️  Data already exists, skipping insert.")

conn.commit()
conn.close()

print(f"✅ Database ready at: {DB_PATH}")