From 102d696ffeb9e50a1becdd5f4a4b829982461f00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Frans=20Pondaco=20Winandy?=
 <jvfpw18@inf.ufpr.br>
Date: Mon, 27 May 2019 09:26:33 -0300
Subject: [PATCH] Better support for multiple tables update

---
 database/database_table.py | 19 ++++++++++---------
 requirements.txt           |  2 +-
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/database/database_table.py b/database/database_table.py
index d97bf54..e5a083c 100644
--- a/database/database_table.py
+++ b/database/database_table.py
@@ -532,13 +532,13 @@ class DatabaseTable(Table):
 
     def transfer_data(self, connection, transfer_list):
         '''
-        Receives a list of columns to be transfered. Transfered columns are backed up,
-        removed, added with new parameters and then repopulated.
-        transfer_list must be a list of dictionaries with the following fields:
-        name - the name of the original column;
-        new_name - name for the new column. If None is passed, original name is used;
-        new_type - type for the new column. If None is passed, original type is used.
-        '''
+             Receives a list of columns to be transfered. Transfered columns are backed up,
+             removed, added with new parameters and then repopulated.
+             transfer_list must be a list of dictionaries with the following fields:
+             name - the name of the original column;
+             new_name - name for the new column. If None is passed, original name is used;
+             new_type - type for the new column. If None is passed, original type is used.
+             '''
         if not transfer_list:
             return
         pk_columns = list(self.primary_key.columns)
@@ -570,9 +570,10 @@ class DatabaseTable(Table):
 
         values = {}
         for item in transfer_list:
-            temp_columns = [column for column in ttable.columns if column.key == item['new_name']]
-            values[item['new_name']] = select(temp_columns).where(list(self.primary_key.columns) == temp_pk_columns)
+            values[item['new_name']] = ttable.columns.get(item['new_name'])
         base_update = update(self).values(**values)
+        for original_pk, temp_pk in zip(list(self.primary_key.columns), temp_pk_columns):
+            base_update = base_update.where(original_pk == temp_pk)
 
         connection.execute(base_update)
 
diff --git a/requirements.txt b/requirements.txt
index 4ed7cb9..17b7dfa 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -25,7 +25,7 @@ pytz==2017.2
 simplegeneric==0.8.1
 six==1.11.0
 SQLAlchemy==1.2.19
-sqlalchemy-monetdb==1.0.0
+-e git://github.com/jvwinandy/sqlalchemy-monetdb.git@1.0.1#egg=sqlalchemy-monetdb
 traitlets==4.3.2
 wcwidth==0.1.7
 wrapt==1.10.10
-- 
GitLab