Replace cursor fetchall by iteration over cursor

issue5817
review335831003
This commit is contained in:
Cédric Krier committed 2021-03-21 16:09:13 +01:00
1 parent 029396e950
commit a1698aafbb
2 files changed
+7 -5

No files matched your search

+6 -4
View File
@@ -72,7 +72,9 @@ class Line(ModelSQL, ModelView):
@classmethod
def __register__(cls, module_name):
cursor = Transaction().connection.cursor()
transaction = Transaction()
cursor = transaction.connection.cursor()
update = transaction.connection.cursor()
table = cls.__table_handler__(module_name)
sql_table = cls.__table__()
pool = Pool()
@@ -86,7 +88,7 @@ class Line(ModelSQL, ModelView):
# Migration from 3.4: new company field
if created_company:
# Don't use FROM because SQLite nor MySQL support it.
cursor.execute(*sql_table.update(
update.execute(*sql_table.update(
[sql_table.company], [work.select(work.company,
where=work.id == sql_table.work)]))
# Migration from 3.4: change hours into timedelta duration
@@ -94,9 +96,9 @@ class Line(ModelSQL, ModelView):
table.drop_constraint('check_move_hours_pos')
cursor.execute(*sql_table.select(
sql_table.id, sql_table.hours))
for id_, hours in cursor.fetchall():
for id_, hours in cursor:
duration = datetime.timedelta(hours=hours)
cursor.execute(*sql_table.update(
update.execute(*sql_table.update(
[sql_table.duration],
[duration],
where=sql_table.id == id_))
+1 -1
View File
@@ -158,7 +158,7 @@ class Work(DeactivableMixin, ModelSQL, ModelView):
cursor.execute(*query_table.select(table_w.id, Sum(line.duration),
where=red_sql & where,
group_by=table_w.id))
for work_id, duration in cursor.fetchall():
for work_id, duration in cursor:
# SQLite uses float for SUM
if duration and not isinstance(duration, datetime.timedelta):
duration = datetime.timedelta(seconds=duration)