Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- con = sqlite3.connect("my_database.db")
- cursor = con.cursor()
- def create_student_table(con):
- con = sqlite3.connect("my_database.db")
- cur = con.cursor()
- cur.execute("CREATE TABLE IF NOT EXISTS students(roll_no INTEGER PRIMARY KEY, name TEXT,"
- " age INTEGER, course TEXT, email TEXT, phone INTEGER)")
- con.commit()
- def insert_student_table(roll_no, name, age, course, email, phone):
- con = sqlite3.connect("my_database.db")
- cur = con.cursor()
- cur.execute("INSERT INTO students VALUES(?, ?, ?, ?, ?, ?)", (roll_no, name, age, course, email, phone))
- con.commit()
- create_student_table(con)
- insert_student_table(1, 'Wendy', 17, 'English Language', 'charles10@gmail.com', 8032435676)
- insert_student_table(2, 'Peter', 15, 'Chemical Engineering', 'peter20@yahoo.com', 9076565434)
- insert_student_table(3, 'Mercy', 19, 'Theatre Arts', 'mercy30@gmail.com', 8123456454)
- insert_student_table(4, 'Micheal', 16, 'Accounting', 'micheal40@gmail,com', 7045342110)
- insert_student_table(5, 'Tina', 20, 'Statistics', 'tina50@yahoo.com', 8123456000)
- class Select():
- def view_student_table(self):
- con = sqlite3.connect("my_database.db")
- cur = con.cursor()
- for row in cursor.execute("SELECT roll_no, name, age, course, email, phone"):
- print("Roll_no = ", row[0])
- print("Name = ", row[1])
- print("Age = ", row[2])
- print("Course = ", row[3])
- print("Email = ", row[4])
- print("Phone = ", row[5],
- "\n")
- con.commit()
- class Fetch(Select):
- def fetch_student_table(self):
- con = sqlite3.connect("my_database.db")
- cur = con.cursor()
- [print(row) for row in cursor.fetchall() ]
- def update_student_table():
- con = sqlite3.connect("my_database.db")
- cur = con.cursor()
- pass
- def delete_student_table():
- con = sqlite3.connect("my_database.db")
- cur = con.cursor()
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement