Spaces:
Sleeping
Sleeping
Update database.py
Browse files- database.py +0 -100
database.py
CHANGED
|
@@ -1,103 +1,3 @@
|
|
| 1 |
-
# import sqlite3
|
| 2 |
-
|
| 3 |
-
# # Create and initialize the database
|
| 4 |
-
# def initialize_database():
|
| 5 |
-
# conn = sqlite3.connect("college.db")
|
| 6 |
-
# cursor = conn.cursor()
|
| 7 |
-
|
| 8 |
-
# # Create student table
|
| 9 |
-
# cursor.execute("""
|
| 10 |
-
# CREATE TABLE IF NOT EXISTS student (
|
| 11 |
-
# student_id INTEGER PRIMARY KEY,
|
| 12 |
-
# first_name TEXT,
|
| 13 |
-
# last_name TEXT,
|
| 14 |
-
# date_of_birth DATE,
|
| 15 |
-
# email TEXT,
|
| 16 |
-
# phone_number TEXT,
|
| 17 |
-
# major TEXT,
|
| 18 |
-
# year_of_enrollment INTEGER
|
| 19 |
-
# );
|
| 20 |
-
# """)
|
| 21 |
-
|
| 22 |
-
# # Create employee table
|
| 23 |
-
# cursor.execute("""
|
| 24 |
-
# CREATE TABLE IF NOT EXISTS employee (
|
| 25 |
-
# employee_id INTEGER PRIMARY KEY,
|
| 26 |
-
# first_name TEXT,
|
| 27 |
-
# last_name TEXT,
|
| 28 |
-
# email TEXT,
|
| 29 |
-
# department TEXT,
|
| 30 |
-
# position TEXT,
|
| 31 |
-
# salary REAL,
|
| 32 |
-
# date_of_joining DATE
|
| 33 |
-
# );
|
| 34 |
-
# """)
|
| 35 |
-
|
| 36 |
-
# # Create course_info table
|
| 37 |
-
# cursor.execute("""
|
| 38 |
-
# CREATE TABLE IF NOT EXISTS course (
|
| 39 |
-
# course_id INTEGER PRIMARY KEY,
|
| 40 |
-
# course_name TEXT,
|
| 41 |
-
# course_code TEXT,
|
| 42 |
-
# instructor_id INTEGER,
|
| 43 |
-
# department TEXT,
|
| 44 |
-
# credits INTEGER,
|
| 45 |
-
# semester TEXT
|
| 46 |
-
# );
|
| 47 |
-
# """)
|
| 48 |
-
|
| 49 |
-
# # Insert sample data into student table
|
| 50 |
-
# cursor.execute("DELETE FROM student;")
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# cursor.executemany("INSERT OR IGNORE INTO student VALUES (?, ?, ?, ?, ?, ?, ?, ?);", [
|
| 55 |
-
# (1, "Alice", "Johnson", "2001-06-15", "alice@example.com", "1234567890", "Computer Science", 2019),
|
| 56 |
-
# (2, "Bob", "Smith", "2000-04-22", "bob@example.com", "0987654321", "Mechanical Engineering", 2018),
|
| 57 |
-
# ])
|
| 58 |
-
|
| 59 |
-
# # Insert sample data into employee table
|
| 60 |
-
# cursor.execute("DELETE FROM employee;")
|
| 61 |
-
# cursor.executemany("INSERT OR IGNORE INTO employee VALUES (?, ?, ?, ?, ?, ?, ?, ?);", [
|
| 62 |
-
# (1, "Drake", "Miller", "drake@example.com", "CSE", "Professor", 75000.00, "2015-08-01"),
|
| 63 |
-
# (2, "Laura", "White", "laura@example.com", "ECE", "Assistant Professor", 65000.00, "2018-07-10"),
|
| 64 |
-
# ])
|
| 65 |
-
|
| 66 |
-
# # Insert sample data into course_info table
|
| 67 |
-
# cursor.execute("DELETE FROM course;")
|
| 68 |
-
# cursor.executemany("INSERT OR IGNORE INTO course VALUES (?, ?, ?, ?, ?, ?, ?);", [
|
| 69 |
-
# (1, "Database Systems", "CS301", 1, "CSE", 4, "Fall"),
|
| 70 |
-
# (2, "Digital Electronics", "EC202", 1, "ECE", 3, "Spring"),
|
| 71 |
-
# ])
|
| 72 |
-
|
| 73 |
-
# conn.commit()
|
| 74 |
-
# conn.close()
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
# # Function to execute SQL query and return results
|
| 78 |
-
# def run_sql_query(sql_query):
|
| 79 |
-
# try:
|
| 80 |
-
# conn = sqlite3.connect("college.db")
|
| 81 |
-
# cursor = conn.cursor()
|
| 82 |
-
# cursor.execute(sql_query)
|
| 83 |
-
# rows = cursor.fetchall()
|
| 84 |
-
# column_names = [description[0] for description in cursor.description] if cursor.description else []
|
| 85 |
-
# conn.commit()
|
| 86 |
-
# conn.close()
|
| 87 |
-
|
| 88 |
-
# if not rows:
|
| 89 |
-
# return "No rows returned."
|
| 90 |
-
|
| 91 |
-
# result = "\t".join(column_names) + "\n"
|
| 92 |
-
# for row in rows:
|
| 93 |
-
# result += "\t".join(str(cell) for cell in row) + "\n"
|
| 94 |
-
# return result.strip()
|
| 95 |
-
# except Exception as e:
|
| 96 |
-
# return f"Error executing query: {e}"
|
| 97 |
-
|
| 98 |
-
# # Initialize database when this script runs directly
|
| 99 |
-
# if __name__ == "__main__":
|
| 100 |
-
# initialize_database()
|
| 101 |
import sqlite3
|
| 102 |
|
| 103 |
# Create and initialize the database
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import sqlite3
|
| 2 |
|
| 3 |
# Create and initialize the database
|