changeset d5bd5090b474 in modules/timesheet:default
details: https://hg.tryton.org/modules/timesheet?cmd=changeset&node=d5bd5090b474
description:
Replace cursor fetchall by iteration over cursor
issue5817
review335831003
diffstat:
line.py | 10 ++++++----
work.py | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
diffs (47 lines):
diff -r fca40742c793 -r d5bd5090b474 line.py
--- a/line.py Thu Mar 11 19:08:45 2021 +0100
+++ b/line.py Sun Mar 21 16:09:13 2021 +0100
@@ -72,7 +72,9 @@
@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 @@
# 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 @@
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_))
diff -r fca40742c793 -r d5bd5090b474 work.py
--- a/work.py Thu Mar 11 19:08:45 2021 +0100
+++ b/work.py Sun Mar 21 16:09:13 2021 +0100
@@ -158,7 +158,7 @@
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)