equal
deleted
inserted
replaced
26 import io |
26 import io |
27 |
27 |
28 |
28 |
29 class TargetNotEmptyError(Exception): |
29 class TargetNotEmptyError(Exception): |
30 |
30 |
31 pass |
31 def __init__(self, msg, table): |
|
32 Exception.__init__(self, msg) |
|
33 self.table = table |
32 |
34 |
33 |
35 |
34 class PgDataCopy: |
36 class PgDataCopy: |
35 |
37 |
36 def __init__(self, conn1, conn2): |
38 def __init__(self, conn1, conn2): |
72 q = self._compose_check(self.fulltable2) |
74 q = self._compose_check(self.fulltable2) |
73 curs = self.conn2.cursor() |
75 curs = self.conn2.cursor() |
74 curs.execute(q) |
76 curs.execute(q) |
75 curs.connection.commit() |
77 curs.connection.commit() |
76 if curs.rowcount > 0: |
78 if curs.rowcount > 0: |
77 raise TargetNotEmptyError('Target table contains data: %s' % self.fulltable2) |
79 raise TargetNotEmptyError('Target table contains data.', self.fulltable2) |
78 self.cols = [desc[0] for desc in curs.description] |
80 self.cols = [desc[0] for desc in curs.description] |
79 |
81 |
80 def read(self, tmpfile): |
82 def read(self, tmpfile): |
81 '''Read contents from source table.''' |
83 '''Read contents from source table.''' |
82 q = self._compose_read(self.fulltable1, self.cols) |
84 q = self._compose_read(self.fulltable1, self.cols) |