Commit 3d4acf58 authored by Clement Lucas's avatar Clement Lucas
Browse files

Ajout fonction rechercher_correspondance()

parent dd267259
from SQL import SQL
class Client(SQL):
......@@ -28,6 +27,59 @@ class Client(SQL):
''' % (ville_depart,ville_arrivee)
return self._requete_sql(sql)
def rechercher_correspondance(self, ville_depart, ville_arrivee):
sql_1='''
SELECT ligne, id_arret
FROM arret
INNER JOIN gare
ON arret.gare = gare.id_gare
WHERE gare.nom_ville = '%s';
''' % ville_depart
rows_1 = self._requete_sql(sql_1)
for row_1 in rows_1:
sql_2 ='''
SELECT gare
FROM arret
WHERE ligne = %d
AND id_arret > %d
''' % (row_1[0],row_1[1])
rows_2 = self._requete_sql(sql_2)
for row_2 in rows_2:
sql_3 ='''
SELECT nom_ville
FROM gare
WHERE id_gare = %d;
''' % row_2[0]
rows_3 = self._requete_sql(sql_3)
for row_3 in rows_3:
sql_4 ='''
SELECT ligne, id_arret
FROM arret
INNER JOIN gare
ON arret.gare = gare.id_gare
WHERE gare.nom_ville = '%s'
AND ligne <> %d;
''' % (row_3[0],row_1[0])
rows_4 = self._requete_sql(sql_4)
for row_4 in rows_4:
sql_5 ='''
SELECT gare.nom_ville
FROM arret
INNER JOIN gare
ON gare.id_gare = arret.gare
WHERE arret.ligne = %d
AND arret.id_arret > %d
AND gare.nom_ville <> '%s';
''' % (row_4[0],row_4[1],ville_depart)
rows_5 = self._requete_sql(sql_5)
for row_5 in rows_5:
if (row_5[0] == ville_arrivee):
print("Depuis %s empruntez la ligne %d jusque %s, puis empruntez la ligne %d jusque %s" %(ville_depart,row_1[0],row_3[0],row_4[0],ville_arrivee))
return
p = Client()
p.rechercher_correspondance('Paris','Toulouse')
......
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