pgtoolkit/pgdatadiff.py
changeset 41 6aad5e35efe8
parent 31 c2e6e24b83d9
child 54 291473ab847c
--- a/pgtoolkit/pgdatadiff.py	Fri Aug 17 11:07:22 2012 +0200
+++ b/pgtoolkit/pgdatadiff.py	Fri Aug 17 11:14:31 2012 +0200
@@ -162,26 +162,29 @@
         '''
         curs1, curs2 = self._select()
         
-        row1 = curs1.fetchone_adapted()
-        row2 = curs2.fetchone_adapted()
+        row1 = curs1.fetchone_dict()
+        row2 = curs2.fetchone_dict()
         
         while True:
             if row1 is None and row2 is None:
                 break
-            diff = self._compare_row(row1, row2)
+            diff = self._compare_row(row1, row2, curs1.adapt, curs2.adapt)
             
             if diff:
                 yield diff
             
                 if diff.change == '-':
-                    row1 = curs1.fetchone_adapted()
+                    row1 = curs1.fetchone_dict()
                     continue
                 if diff.change == '+':
-                    row2 = curs2.fetchone_adapted()
+                    row2 = curs2.fetchone_dict()
                     continue
             # change == '*' or not diff
-            row1 = curs1.fetchone_adapted()
-            row2 = curs2.fetchone_adapted()
+            row1 = curs1.fetchone_dict()
+            row2 = curs2.fetchone_dict()
+        
+        curs1.close()
+        curs2.close()
     
     def print_diff(self):
         '''Print differencies between data of two tables.
@@ -222,8 +225,8 @@
         query1 = 'SELECT ' + columns_sel + ' FROM ' + self.fulltable1 + ' ORDER BY ' + pkey_sel
         query2 = 'SELECT ' + columns_sel + ' FROM ' + self.fulltable2 + ' ORDER BY ' + pkey_sel
         
-        curs1 = self.conn1.cursor()
-        curs2 = self.conn2.cursor()
+        curs1 = self.conn1.cursor('curs1')
+        curs2 = self.conn2.cursor('curs2')
         
         curs1.execute(query1)
         curs2.execute(query2)
@@ -243,21 +246,26 @@
         
         return None
     
-    def _compare_row(self, row1, row2):
+    def _compare_row(self, row1, row2, adapt1, adapt2):
         if row2 is None:
+            row1 = adapt1(row1)
             key = OrderedDict(zip(self.pkeycolnames, [row1[colname] for colname in self.pkeycolnames]))
             return DiffData('-', row1, None, key=key)
         if row1 is None:
+            row2 = adapt2(row2)
             return DiffData('+', None, row2)
         
-        
         for keyname in self.pkeycolnames:
             if row1[keyname] < row2[keyname]:
+                row1 = adapt1(row1)
                 key = OrderedDict(zip(self.pkeycolnames, [row1[colname] for colname in self.pkeycolnames]))
                 return DiffData('-', row1, None, key=key)
         for keyname in self.pkeycolnames:
             if row1[keyname] > row2[keyname]:
+                row2 = adapt2(row2)
                 return DiffData('+', None, row2)
         
+        row1 = adapt1(row1)
+        row2 = adapt2(row2)
         return self._compare_data(row1, row2)