changeset 81aca820f1d0 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset&node=81aca820f1d0
description:
        Replace cursor fetchall by iteration over cursor

        issue5817
        review335831003
diffstat:

 product.py        |  8 +++++---
 sale.py           |  2 +-
 sale_reporting.py |  4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diffs (58 lines):

diff -r 303fc74af291 -r 81aca820f1d0 product.py
--- a/product.py        Thu Mar 11 23:00:10 2021 +0100
+++ b/product.py        Sun Mar 21 16:09:13 2021 +0100
@@ -56,7 +56,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__()
 
@@ -66,11 +68,11 @@
         if table.column_exist('delivery_time'):
             cursor.execute(*sql_table.select(
                     sql_table.id, sql_table.delivery_time))
-            for id_, delivery_time in cursor.fetchall():
+            for id_, delivery_time in cursor:
                 if delivery_time is None:
                     continue
                 lead_time = datetime.timedelta(days=delivery_time)
-                cursor.execute(*sql_table.update(
+                update.execute(*sql_table.update(
                         [sql_table.lead_time],
                         [lead_time],
                         where=sql_table.id == id_))
diff -r 303fc74af291 -r 81aca820f1d0 sale.py
--- a/sale.py   Thu Mar 11 23:00:10 2021 +0100
+++ b/sale.py   Sun Mar 21 16:09:13 2021 +0100
@@ -1790,7 +1790,7 @@
         sale = Sale.__table__()
 
         cursor.execute(*sale.select(sale.party, group_by=sale.party))
-        customer_ids = [line[0] for line in cursor.fetchall()]
+        customer_ids = [line[0] for line in cursor]
         action['pyson_domain'] = PYSONEncoder().encode(
             [('id', 'in', customer_ids)])
         wizard = Wizard(ModelData.get_id('sale', 'act_open_customer'))
diff -r 303fc74af291 -r 81aca820f1d0 sale_reporting.py
--- a/sale_reporting.py Thu Mar 11 23:00:10 2021 +0100
+++ b/sale_reporting.py Sun Mar 21 16:09:13 2021 +0100
@@ -532,12 +532,12 @@
             sub_ids = list(sub_ids)
             where = reduce_ids(table.id, sub_ids)
             cursor.execute(*table.select(table.id, table.parent, where=where))
-            parents.update(cursor.fetchall())
+            parents.update(cursor)
 
             where = reduce_ids(reporting_category.id, sub_ids)
             cursor.execute(
                 *reporting_category.select(reporting_category.id, where=where))
-            reporting_categories.extend(r for r, in cursor.fetchall())
+            reporting_categories.extend(r for r, in cursor)
 
         result = {}
         reporting_categories = ReportingCategory.browse(reporting_categories)

Reply via email to