Exemple #1
0
    def get_existing_tables(self):
        with DBConnection() as connection:
            cursor = connection.cursor()
            cursor.execute("SELECT * FROM sqlite_master WHERE type='table'")
            records = cursor.fetchall()

        return [single_row["tbl_name"] for single_row in records]
Exemple #2
0
 def insert_a_subject(self, stu_id, subject, score):
     command = "INSERT INTO subject_info (stu_id, subject, score) VALUES  ('{}', '{}', {});".format(stu_id, subject, score)
         
     with DBConnection() as connection:
         cursor = connection.cursor()
         cursor.execute(command)
         connection.commit()
Exemple #3
0
    def update_a_subject(self, stu_id, subject, score):
        command = "UPDATE subject_info SET score='{}' WHERE stu_id='{}' AND  subject='{}';".format(score, stu_id, subject)

        with DBConnection() as connection:
            cursor = connection.cursor()
            cursor.execute(command)
            connection.commit()
Exemple #4
0
    def delete_a_subject(self, stu_id):
        command = "DELETE FROM subject_info WHERE stu_id='{}';".format(stu_id)

        with DBConnection() as connection:
            cursor = connection.cursor()
            cursor.execute(command)
            connection.commit()
Exemple #5
0
    def select_a_subject(self, stu_id, subject):
        command = "SELECT * FROM subject_info WHERE stu_id = '{}' AND subject='{}';".format(stu_id, subject)

        with DBConnection() as connection:
            cursor = connection.cursor()
            cursor.execute(command)
            record_from_db = cursor.fetchall()

        return [row['score'] for row in record_from_db]
Exemple #6
0
    def show_all_subjects(self, stu_id) :
        command = "SELECT DISTINCT subject FROM subject_info WHERE stu_id='{}';".format(stu_id)

        with DBConnection() as connection:
            cursor = connection.cursor()
            cursor.execute(command)
            connection.commit()
            record_from_db = cursor.fetchall()

        return [row['subject'] for row in record_from_db]
Exemple #7
0
 def create_table_with_specefied_command(self, command):
     with DBConnection() as connection:
         cursor = connection.cursor()
         cursor.execute(command)
         connection.commit()