Commit c89c7a73 authored by Antoine Kryus's avatar Antoine Kryus
Browse files

add delete data function with pretty print (tabulate)

parent 814e9ec2
......@@ -7,4 +7,4 @@ def add(conn):
cur = conn.cursor()
# afficher les tables
table = input("Entrer le nom de la table où ajouter des données \n (Association, Inscription, Role, Billet, CategorieBillet, MembreDeLUniversite, MembreExterieur, Batiment, Salle, Spectacle, Seance) \n")
#!/usr/bin/python3
import psycopg2
from tabulate import tabulate
def delete(conn):
cur = conn.cursor()
column_names = []
data_rows = []
# afficher les tables
table = input("\nEntrer le nom de la table de la ou les données à supprimer :\n(Association, Inscription, Role, Billet, CategorieBillet, MembreDeLUniversite, MembreExterieur, Batiment, Salle, Spectacle, Seance) \n-> ")
# afficher la table sélectionnée pour se repérer
print("\n")
sql = "SELECT * FROM " + table + ";"
cur.execute(sql)
nb_field = len(cur.description)
column_names = [desc[0] for desc in cur.description]
for row in cur:
data_rows.append(row)
print (tabulate(data_rows, headers=column_names))
condition = input("Entrez la condition (par exemple nom='jean-marc' supprimera la ligne de jean-marc) : \n-> ")
sql = "DELETE FROM " + table + " WHERE " + condition + ";"
cur.execute(sql)
conn.commit()
......@@ -28,8 +28,8 @@ while option != 0:
add.add(conn)
elif option == 2:
display.display(conn)
# elif option == 3:
# delete.delete(conn)
elif option == 3:
delete.delete(conn)
# elif option == 4:
# update.update(conn)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment