Commit 6aff1b27 authored by Lingfeng Huang's avatar Lingfeng Huang

Update prog.py

parent 17b68fa6
......@@ -153,12 +153,11 @@ CONTROLLER FUCNTIONS SECTION
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
"""
def afficherTable(conn,table):
sql = "SELECT * FROM "+table
def afficherSql(conn,sql):
try:
cur.execute(sql)
except pg.Error:
print("Execute Error")
except psycopg2.Error as e:
print("Execute: ",e)
conn.rollback()
return
# Fetch data line by line
......@@ -166,15 +165,58 @@ def afficherTable(conn,table):
raw = cur.fetchone()
if raw:
while raw:
print (raw[0])
print (raw[1])
for i in raw:
print(i,end=", ")
print("")
raw = cur.fetchone()
else:
print("Empty table")
conn.commit()
except pg.Error:
except psycopg2.Error:
print("Fetch error")
conn.rollback()
def afficherStatistique(conn):
sql=""
while True:
choix=0
print("1.Selection des prescriptions d'un animal (pas demandé mais aide à l'analyse de la statistique")
print("2.Statistique medicament pour un animal")
print("3.Statistique quantite prescrite pour un medicament particulier")
print("4.Poids moyen par espèce ")
print("5.Taille moyenne par espèce ")
print("6.Quitter")
choix=int(input())
if (choix==1):
id=input("Entrez ID d'animal: ");
sql="SELECT P.medicament, P.quantite FROM Prescriptions P, Traitements T WHERE T.animal = "+str(id)+" AND P.traitement = T.id"
elif(choix==2):
id=input("Entrez ID d'animal: ");
sql="SELECT P.medicament, SUM(P.quantite) FROM Traitements T, Prescriptions P WHERE T.animal = "+str(id)+ "AND P.traitement = T.id GROUP BY P.medicament"
elif(choix==3):
nomMolecule=input("Entrez nom de molecule: ");
sql="SELECT SUM(P.quantite) AS quantite_prescrite FROM Prescriptions P WHERE P.medicament = \""+nomMolecule+"\""
elif(choix==4):
sql="SELECT M.nomMolecule, SUM(P.quantite) AS quantite_prescrite FROM Prescriptions P, Medicaments M WHERE P.medicament = M.nomMolecule GROUP BY M.nomMolecule;"
elif(choix==5):
sql="SELECT A.espece, AVG(A.derniereTaille) AS taille_moyenne FROM animaux A GROUP BY A.espece"
if sql:
afficherSql(conn,sql)
if choix>5 or choix<1:
return
def afficherTable(conn):
while True:
sql=""
tables=["classes","especes","clients","veterinaires","assistants","animaux","proprietaires","medicaments","traitements","prescriptions"]
table=input("Entrez le nom du table:")
if not table:
return
if table.lower() in tables:
sql="SELECT * FroM "+ table
afficherSql(conn,sql)
return True
def modifierTables(table)
def afficherTables(table)
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