j'ai mis des try finally partout

This commit is contained in:
Alice 2018-02-07 13:05:47 +01:00
parent b411dc85e2
commit edf405c580

View file

@ -26,60 +26,64 @@ class filmSQ():
self.idN = dic['idN']
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('INSERT INTO films VALUES (:i, :idN, :date, :nom, realisateur, :duree, :synopsis, :pays, :annee, :youtube, :couleur, :image, :formatCopie, :langST)', dic)
c.execute('INSERT INTO films VALUES (:i, :idN, :date, :nom, realisateur, :duree, :synopsis, :pays, :annee, :youtube, :couleur, :image, :formatCopie, :langST)', dic)
acteursToSq = [{'idFilm' : self.i, 'acteur' : a} for a in dic['acteurs']]
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
conn.close()
acteursToSq = [{'idFilm' : self.i, 'acteur' : a} for a in dic['acteurs']]
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
finally:
conn.close()
#id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT [PRIMARY KEY]
def __setattr__(self, nom_attr, val_attr):
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
if nom_attr == 'acteurs':
c.execute('DELETE FROM acteurs WHERE idFilm =?', (self.i))
acteursToSq = [{'idFilm' : self.i, 'acteur' : a} for a in val_attr]
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
else:
c.execute('UPDATE films SET ? = ? WHERE idN = ?', (nom_attr, val_attr, self.idN))
conn.close()
try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
if nom_attr == 'acteurs':
c.execute('DELETE FROM acteurs WHERE idFilm =?', (self.i))
acteursToSq = [{'idFilm' : self.i, 'acteur' : a} for a in val_attr]
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
else:
c.execute('UPDATE films SET ? = ? WHERE idN = ?', (nom_attr, val_attr, self.idN))
finally:
conn.close()
def __getattr__(self, nom):
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
if nom == 'acteurs':
c.execute('SELECT :acteur FROM acteurs WHERE idFilms=?', (self.i))
r = c.fetchall()
res = [a[0] for a in r]
else:
c.execute('SELECT :nom_attr FROM films WHERE idN=:idN', {"idN":self.idN, "nom_attr":nom})
r = c.fetchone()
res = r[0]
conn.close()
try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
if nom == 'acteurs':
c.execute('SELECT :acteur FROM acteurs WHERE idFilms=?', (self.i))
r = c.fetchall()
res = [a[0] for a in r]
else:
c.execute('SELECT :nom_attr FROM films WHERE idN=:idN', {"idN":self.idN, "nom_attr":nom})
r = c.fetchone()
res = r[0]
finally:
conn.close()
return res
def __str__(self):
conn = sqlite3.connect("baseFilms.db")
try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT (?,?,?) FROM films WHERE idN = ?', ('idN', 'nom', 'date', self.idN))
r = c.fetchone()
s = r[0] + ' : ' + r[1] + ' le ' + r[2]
conn.close()
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT (?,?,?) FROM films WHERE idN = ?', ('idN', 'nom', 'date', self.idN))
r = c.fetchone()
s = r[0] + ' : ' + r[1] + ' le ' + r[2]
finally:
conn.close()
return s
@ -184,28 +188,30 @@ class filmSQ():
return res
def maxId():
conn = sqlite3.connect("baseFilms.db")
try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT MAX(i) FROM films')
r = c.fetchone()
conn.close()
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT MAX(i) FROM films')
r = c.fetchone()
finally:
conn.close()
return r[0]
def printAll():
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT idN FROM films ORDER_BY i')
r = c.fetchall()
for movie in r:
print(r[0] + ' : ' + r[1] + ' le ' + r[2])
conn.close()
try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute('SELECT idN FROM films ORDER_BY i')
r = c.fetchall()
for movie in r:
print(r[0] + ' : ' + r[1] + ' le ' + r[2])
finally:
conn.close()
pass
def strListe(liste):