réparation lmerge

This commit is contained in:
Alice 2018-02-07 20:46:38 +01:00
commit 46216b6507
2 changed files with 50 additions and 46 deletions

3
TODO.md Normal file
View file

@ -0,0 +1,3 @@
* mise en forme date
* débug
* remplissage

View file

@ -46,6 +46,7 @@ class filmSQ():
if nom_attr == 'idN': if nom_attr == 'idN':
res= object.__setattr__(self, 'idN', val_attr) res= object.__setattr__(self, 'idN', val_attr)
else: else:
try:
conn = sqlite3.connect("baseFilms.db") conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
c = conn.cursor() c = conn.cursor()
@ -57,14 +58,12 @@ class filmSQ():
else: else:
c.execute('UPDATE films SET ? = ? WHERE idN = ?', (nom_attr, val_attr, self.idN)) c.execute('UPDATE films SET ? = ? WHERE idN = ?', (nom_attr, val_attr, self.idN))
conn.commit() finally:
c.close() c.commit()
conn.close()
def __getattr__(self, nom): def __getattr__(self, nom):
try:
if nom == 'idN':
res= object.__getattr__(self, idN)
else:
conn = sqlite3.connect("baseFilms.db") conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
c = conn.cursor() c = conn.cursor()
@ -77,21 +76,22 @@ class filmSQ():
r = c.fetchone() r = c.fetchone()
res = r[0] res = r[0]
finally:
c.commit()
conn.close() conn.close()
return res return res
def __str__(self): def __str__(self):
try:
conn = sqlite3.connect("baseFilms.db") conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
c = conn.cursor() c = conn.cursor()
c.execute('SELECT (?,?,?) FROM films WHERE idN = ?', ('idN', 'nom', 'date', self.idN)) c.execute('SELECT (?,?,?) FROM films WHERE idN = ?', ('idN', 'nom', 'date', self.idN))
r = c.fetchone() r = c.fetchone()
s = r[0] + ' : ' + r[1] + ' le ' + r[2] s = r[0] + ' : ' + r[1] + ' le ' + r[2]
finally:
conn.commit() conn.close()
c.close()
return s return s
@ -196,18 +196,20 @@ class filmSQ():
return res return res
def maxId(): def maxId():
try:
conn = sqlite3.connect("baseFilms.db") conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
c = conn.cursor() c = conn.cursor()
c.execute('SELECT MAX(i) FROM films') c.execute('SELECT MAX(i) FROM films')
r = c.fetchone() r = c.fetchone()
finally:
conn.close() conn.close()
return r[0] return r[0]
def printAll(): def printAll():
try:
conn = sqlite3.connect("baseFilms.db") conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
@ -216,9 +218,8 @@ class filmSQ():
r = c.fetchall() r = c.fetchall()
for movie in r: for movie in r:
print(r[0] + ' : ' + r[1] + ' le ' + r[2]) print(r[0] + ' : ' + r[1] + ' le ' + r[2])
finally:
conn.commit() conn.close()
c.close()
pass pass
def strListe(liste): def strListe(liste):