Spaces:
Runtime error
Runtime error
| import sqlite3 | |
| def init_db(): | |
| conn = sqlite3.connect('sales.db') | |
| c = conn.cursor() | |
| # Create Tables | |
| c.execute('''CREATE TABLE IF NOT EXISTS customers | |
| (id INTEGER PRIMARY KEY, name TEXT, region TEXT)''') | |
| c.execute('''CREATE TABLE IF NOT EXISTS products | |
| (id INTEGER PRIMARY KEY, name TEXT, category TEXT, price REAL)''') | |
| c.execute('''CREATE TABLE IF NOT EXISTS orders | |
| (id INTEGER PRIMARY KEY, customer_id INTEGER, product_id INTEGER, | |
| quantity INTEGER, order_date DATE)''') | |
| # Insert Dummy Data | |
| c.execute("INSERT OR IGNORE INTO customers VALUES (1, 'Acme Corp', 'North')") | |
| c.execute("INSERT OR IGNORE INTO customers VALUES (2, 'Globex', 'West')") | |
| c.execute("INSERT OR IGNORE INTO products VALUES (1, 'AI Widget', 'Software', 1000.0)") | |
| c.execute("INSERT OR IGNORE INTO products VALUES (2, 'Cloud Server', 'Hardware', 5000.0)") | |
| c.execute("INSERT OR IGNORE INTO orders VALUES (101, 1, 1, 5, '2023-10-01')") | |
| c.execute("INSERT OR IGNORE INTO orders VALUES (102, 2, 2, 1, '2023-10-05')") | |
| conn.commit() | |
| conn.close() | |
| if __name__ == "__main__": | |
| init_db() |