def createIfNotExist(): db = mysqlConnexion() cur = db.cursor() cur.execute("CREATE DATABASE IF NOT EXISTS vdmdb") cur.execute("CREATE TABLE IF NOT EXISTS game (" "id int auto_increment primary key," "nom varchar(255) not null," "date datetime not null," "vr tinyint(1) not null)") db.close()
def createIfNotExist(): db = mysqlConnexion() cur = db.cursor() cur.execute("CREATE DATABASE IF NOT EXISTS vdmdb") cur.execute("CREATE TABLE IF NOT EXISTS reservation_spectateur (" "id int auto_increment primary key," "id_reservation int(11) not null," "id_spectateur int(11) not null," "tarif varchar(25) not null)") db.close()
def createIfNotExist(): db = mysqlConnexion() cur = db.cursor() cur.execute("CREATE DATABASE IF NOT EXISTS vdmdb") # On crée la table si elle n'existe pas cur.execute("CREATE TABLE IF NOT EXISTS spectateur (" "id int auto_increment primary key," "civilite varchar(10) not null," "nom varchar(25) not null," "prenom varchar(25)," "age int(2))") db.close()
def addReservationSpectateurToSQL(reservation_spectateur): db = mysqlConnexion() query = "insert into reservation_spectateur (id_reservation, id_spectateur, tarif) " \ "values('%d', '%d', '%s')" % (reservation_spectateur.idReservation, reservation_spectateur.idSpectateur, reservation_spectateur.tarif) # print(query) cur = db.cursor() cur.execute(query) reservation_spectateur_id = db.insert_id() db.commit() db.close() return reservation_spectateur_id
def createIfNotExist(): db = mysqlConnexion() cur = db.cursor() cur.execute("CREATE DATABASE IF NOT EXISTS vdmdb") cur.execute("CREATE TABLE IF NOT EXISTS reservation (" "id int auto_increment primary key," "id_acheteur int(11) not null," "id_game int(11) not null," "dateheure datetime not null," "date_prise_reservation datetime not null," "email varchar(50) not null)") db.close()
def addSpectateurToSQL(spectateur): db = mysqlConnexion() query = "insert into spectateur (civilite, nom, prenom, age) " \ "values(%s, %s, %s, %s)" # print(query) cur = db.cursor() cur.execute(query, (spectateur.civilite, spectateur.nom, spectateur.prenom, spectateur.age)) spectateur_id = db.insert_id() db.commit() db.close() return spectateur_id
def addGameToSQL(game): db = mysqlConnexion() query = "insert into game (nom, date, vr) " \ "values(%s, %s, %r)" # print(query) try: cur = db.cursor() cur.execute(query, (game.nom, game.date, game.vr)) game_id = db.insert_id() db.commit() except: print("Failed to add Game") db.close() return game_id
def addReservationToSQL(reservation): db = mysqlConnexion() query = "insert into reservation (id_acheteur, id_game, dateheure, date_prise_reservation, email) " \ "values('%d', '%d', '%s', '%s', '%s')" % (reservation.idSpectateur, reservation.idGame, reservation.dateHeure, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), reservation.email) print(query) try: if "'" in reservation.email: reservation.email = "ERROR" cur = db.cursor() cur.execute(query) reservation_id = db.insert_id() db.commit() except: print("Faild to add reservation") reservation_id = -1 reservation.email = "ERROR" cur = db.cursor() cur.execute(query) reservation_id = db.insert_id() db.commit() finally: db.close() return reservation_id