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,25 +46,24 @@ 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:
conn = sqlite3.connect("baseFilms.db") try:
conn.row_factory = sqlite3.Row conn = sqlite3.connect("baseFilms.db")
c = conn.cursor() conn.row_factory = sqlite3.Row
c = conn.cursor()
if nom_attr == 'acteurs':
c.execute('DELETE FROM acteurs WHERE idFilm =?', (self.i)) if nom_attr == 'acteurs':
acteursToSq = [{'idFilm' : self.i, 'acteur' : a} for a in val_attr] c.execute('DELETE FROM acteurs WHERE idFilm =?', (self.i))
c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq) acteursToSq = [{'idFilm' : self.i, 'acteur' : a} for a in val_attr]
else: c.executemany('INSERT INTO acteurs VALUES (NULL, :idFilm, :acteur)', acteursToSq)
c.execute('UPDATE films SET ? = ? WHERE idN = ?', (nom_attr, val_attr, self.idN)) else:
c.execute('UPDATE films SET ? = ? WHERE idN = ?', (nom_attr, val_attr, self.idN))
conn.commit()
c.close() finally:
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()
@ -76,22 +75,23 @@ class filmSQ():
c.execute('SELECT :nom_attr FROM films WHERE idN=:idN', {"idN":self.idN, "nom_attr":nom}) c.execute('SELECT :nom_attr FROM films WHERE idN=:idN', {"idN":self.idN, "nom_attr":nom})
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):
conn = sqlite3.connect("baseFilms.db") try:
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,29 +196,30 @@ class filmSQ():
return res return res
def maxId(): def maxId():
conn = sqlite3.connect("baseFilms.db") try:
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():
conn = sqlite3.connect("baseFilms.db") try:
conn = sqlite3.connect("baseFilms.db")
conn.row_factory = sqlite3.Row
c = conn.cursor() conn.row_factory = sqlite3.Row
c.execute('SELECT idN FROM films ORDER_BY i') c = conn.cursor()
r = c.fetchall() c.execute('SELECT idN FROM films ORDER_BY i')
for movie in r: r = c.fetchall()
print(r[0] + ' : ' + r[1] + ' le ' + r[2]) for movie in r:
print(r[0] + ' : ' + r[1] + ' le ' + r[2])
conn.commit() finally:
c.close() conn.close()
pass pass
def strListe(liste): def strListe(liste):