Advertisement
Dammiejoy20

Untitled

Apr 23rd, 2020
7,633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import sqlite3
  2. con = sqlite3.connect("my_database.db")
  3.  
  4. cursor = con.cursor()
  5.  
  6. def create_student_table(con):
  7.     con = sqlite3.connect("my_database.db")
  8.     cur = con.cursor()
  9.     cur.execute("CREATE TABLE IF NOT EXISTS students(roll_no INTEGER PRIMARY KEY, name TEXT,"
  10.                    " age INTEGER, course TEXT, email TEXT, phone INTEGER)")
  11.  
  12. con.commit()
  13.  
  14.  
  15.  
  16. def insert_student_table(roll_no, name, age, course, email, phone):
  17.     con = sqlite3.connect("my_database.db")
  18.     cur = con.cursor()
  19.     cur.execute("INSERT INTO students VALUES(?, ?, ?, ?, ?, ?)",  (roll_no, name, age, course, email, phone))
  20. con.commit()
  21.  
  22.  
  23. create_student_table(con)
  24. insert_student_table(1, 'Wendy', 17, 'English Language', 'charles10@gmail.com', 8032435676)
  25. insert_student_table(2, 'Peter', 15, 'Chemical Engineering', 'peter20@yahoo.com', 9076565434)
  26. insert_student_table(3, 'Mercy', 19, 'Theatre Arts', 'mercy30@gmail.com', 8123456454)
  27. insert_student_table(4, 'Micheal', 16, 'Accounting', 'micheal40@gmail,com', 7045342110)
  28. insert_student_table(5, 'Tina', 20, 'Statistics', 'tina50@yahoo.com', 8123456000)
  29.  
  30. class Select():
  31.     def view_student_table(self):
  32.         con = sqlite3.connect("my_database.db")
  33.         cur = con.cursor()
  34.         for row in cursor.execute("SELECT roll_no, name, age, course, email, phone"):
  35.             print("Roll_no = ", row[0])
  36.             print("Name = ", row[1])
  37.             print("Age = ", row[2])
  38.             print("Course = ", row[3])
  39.             print("Email = ", row[4])
  40.             print("Phone = ", row[5],
  41.                   "\n")
  42. con.commit()
  43.  
  44. class Fetch(Select):
  45.     def fetch_student_table(self):
  46.         con = sqlite3.connect("my_database.db")
  47.         cur = con.cursor()
  48.         [print(row) for row in cursor.fetchall() ]
  49.  
  50.  
  51. def update_student_table():
  52.     con = sqlite3.connect("my_database.db")
  53.     cur = con.cursor()
  54.     pass
  55.  
  56.  
  57. def delete_student_table():
  58.     con = sqlite3.connect("my_database.db")
  59.     cur = con.cursor()
  60.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement