예제 #1
0
def create_user(username, emails, password):
    password_hash = generate_password_hash(password)
    db = connect_db()
    try:
        db.execute("INSERT INTO users VALUES(?,?,?)",
                   (username, password_hash, emails))
        db.commit()
    except sqlite3.IntegrityError:
        print >>sys.stderr, "Account already exists"
    finally:
        db.close()
예제 #2
0
def store(result, test, user, zipf):
    with closing(connect_db()) as db:
        c = db.cursor()
        print "Insert into database"
        c.execute("INSERT INTO reports VALUES(?,?)",
                  (None, json.dumps(result["tests"])))
        report_id = c.lastrowid

        c.execute("INSERT INTO grades VALUES(?,?,?,?,?,current_timestamp)",
                  (user,
                   test,
                   result["grade"],
                   report_id,
                   os.path.basename(zipf)))
        db.commit()
예제 #3
0
def init_db():
    install_path = os.path.dirname(os.path.realpath(__file__))
    with closing(connect_db()) as db:
        with open(os.path.join(install_path, "schema.sql")) as f:
            db.cursor().executescript(f.read())
        db.commit()