1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
import mysql.connector
db = mysql.connector.connect(user='root', password='',
host='localhost',
database='testdb')
cur = db.cursor()
chemin = [u'AGA-1128', u'AGA-1017', u'AGA-1016']
ch_troncon = []
for x,col in enumerate(chemin):
for y,col1 in enumerate(chemin):
cur.execute("SELECT ID_TRONCON FROM troncon WHERE SITE_SOMMET = %s AND SITE_ARRET = %s ",(col, col1,))
rows = cur.fetchall()
for row in rows:
ch_troncon.append(row[0])
ch_troncon1 = list(set(ch_troncon))
#print(ch_troncon)
for i,col in enumerate(ch_troncon1):
print(col)
cur.execute("SELECT ID_TRONCON, LONGUEUR, troncon.ZONE, FD, OPEX FROM troncon INNER JOIN hypothese ON troncon.ZONE = hypothese.ZONE WHERE ID_TRONCON = %s ",(col,)) # requête de la jointure
rows = cur.fetchall()
for row in rows:
id_tr = row[0]
print(id_tr) # ce print ne retourne rien :( |
Partager