j'ai mis des try finally partout
This commit is contained in:
parent
b411dc85e2
commit
edf405c580
1 changed files with 64 additions and 58 deletions
|
@ -26,6 +26,7 @@ class filmSQ():
|
|||
|
||||
self.idN = dic['idN']
|
||||
|
||||
try:
|
||||
conn = sqlite3.connect("baseFilms.db")
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
@ -34,12 +35,13 @@ class filmSQ():
|
|||
|
||||
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):
|
||||
try:
|
||||
conn = sqlite3.connect("baseFilms.db")
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
@ -50,10 +52,11 @@ class filmSQ():
|
|||
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):
|
||||
try:
|
||||
conn = sqlite3.connect("baseFilms.db")
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
@ -65,12 +68,13 @@ class filmSQ():
|
|||
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):
|
||||
try:
|
||||
conn = sqlite3.connect("baseFilms.db")
|
||||
|
||||
conn.row_factory = sqlite3.Row
|
||||
|
@ -78,7 +82,7 @@ class filmSQ():
|
|||
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,18 +188,20 @@ class filmSQ():
|
|||
return res
|
||||
|
||||
def maxId():
|
||||
try:
|
||||
conn = sqlite3.connect("baseFilms.db")
|
||||
|
||||
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():
|
||||
try:
|
||||
conn = sqlite3.connect("baseFilms.db")
|
||||
|
||||
conn.row_factory = sqlite3.Row
|
||||
|
@ -204,7 +210,7 @@ class filmSQ():
|
|||
r = c.fetchall()
|
||||
for movie in r:
|
||||
print(r[0] + ' : ' + r[1] + ' le ' + r[2])
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue