Esempio n. 1
0
def quiz_create():
    db = get_db()
    cursor = db.cursor()
    cursor.execute("SELECT * FROM QUIZ_QUESTIONS")
    data = cursor.fetchall()
    db.close()
    return "Creating A quiz"
Esempio n. 2
0
 def get_by_first_name(first_name):
     users = []
     db = get_db()
     cursor = db.cursor()
     cursor.execute(sqlREAD_USER_BY_FIRST_NAME.format(first_name))
     for record in cursor.fetchall():
         users.append(User(record))
     db.close()
     return users
Esempio n. 3
0
 def get_by_id(id):
     db = get_db()
     cursor = db.cursor()
     cursor.execute(sqlREAD_USER.format(id))
     result = cursor.fetchone()
     db.close()
     if result == None:
         return None
     return User(result)
Esempio n. 4
0
 def get_by_username(username):
     db = get_db()
     cursor = db.cursor()
     cursor.execute(sqlREAD_USER_BY_USERNAME.format(username))
     user = cursor.fetchone()
     db.close()
     if user == None:
         return None
     else:
         return User(user)
Esempio n. 5
0
 def add_user(u):
     db = get_db()
     cursor = db.cursor()
     cursor.execute(
         sqlADD_USERS.format(first_name=u.first_name,
                             username=u.username,
                             password=u.password))
     #reload user with ID
     u = User.get_by_username(u.username)
     db.close()
     return u
Esempio n. 6
0
  def get_last_added():
    db = get_db()
    cursor = db.cursor()
    cursor.execute(sqlREAD_PAST_PAPER_LAST_ADDED)
    pp = cursor.fetchone()
    db.close()

    if pp == None:
      return None
    else:
      return PastPaper(pp)
Esempio n. 7
0
  def add_past_paper(u):
    db = get_db()
    cursor = db.cursor()
    cmdSQL = sqlADD_PAST_PAPER.format(level=u.level, 
    year=u.year, 
    month=u.month,
    title=u.title,
    paper_link=u.paper_link,
    ms_link=u.ms_link,
    sols_link=u.sols_link
    )

    cursor.execute(cmdSQL)

    db.commit()
    cursor.execute(sqlREAD_PAST_PAPER_LAST_ADDED)
    #reload user with ID
    pp_data = cursor.fetchone()
    db.close()
    return PastPaper(pp_data)
Esempio n. 8
0
    def get_all():

        db = None
        users = []

        try:
            db = get_db()
            cursor = db.cursor()
            cursor.execute(sqlREAD_USERS)

            results = cursor.fetchall()

            for record in results:
                users.append(User(record))

        except pymysql.err.OperationalError as e:
            current_app.logging.error("The db threw an exception")

        finally:
            if db != None:
                db.close()

            return users
Esempio n. 9
0
 def create_tables():
     db = get_db()
     cursor = db.cursor()
     cursor.execute(sqlDROP_USER_TABLE)
     cursor.execute(sqlCREATE_USER_TABLE)
     db.close()