| 26 | | def test_column_merge(self): |
| 27 | | self.new_cursor.execute("CREATE TABLE a (b INTEGER, c INTEGER)") |
| 28 | | self.old_cursor.execute("CREATE TABLE a (b INTEGER)") |
| | 43 | def _prepare_test(self, new, old): |
| | 44 | table = self.table_name.next() |
| | 45 | self.new_cursor.execute("CREATE TABLE %s (%s)" % (table, new)) |
| | 46 | self.old_cursor.execute("CREATE TABLE %s (%s)" % (table, old)) |
| | 47 | return table |
| 30 | | # I don't care if the pragma table_info still exists or not, if it |
| 31 | | # doesn't then let the test fail. |
| 32 | | |
| 33 | | old_info = self.old_cursor.execute("pragma table_info('a')").fetchall() |
| 34 | | self.failUnlessEqual(len(old_info), 1) |
| | 49 | def _verify_merge(self, new, old): |
| | 50 | table = self._prepare_test(new, old) |
| | 51 | new_table_info = self.new_cursor.execute( |
| | 52 | "pragma table_info(%s)" % table).fetchall() |
| 38 | | old_info = self.old_cursor.execute("pragma table_info('a')").fetchall() |
| 39 | | self.failUnlessEqual(len(old_info), 2) |
| | 56 | # Need to reconnect to get the updated table information. |
| | 57 | conn, cursor = conn_cursor(self.old_db_file.name) |
| | 58 | # I don't care if the pragma table_info still exists or not, if it |
| | 59 | # doesn't then let the test fail. |
| | 60 | old_table_info = cursor.execute( |
| | 61 | "pragma table_info(%s)" % table).fetchall() |
| | 62 | self.failUnlessEqual(len(old_table_info), len(new_table_info)) |
| | 63 | self.failUnlessEqual(old_table_info, new_table_info) |
| | 64 | cursor.close() |
| | 65 | conn.close() |
| | 66 | |
| | 67 | def _verify_merge_fails(self, exc, table, new, old): |
| | 68 | self._prepare_test(table, new, old) |
| | 69 | |
| | 70 | self.failUnlessRaises(exc, |
| | 71 | merge, self.new_db_file.name, self.old_db_file.name) |
| | 72 | |
| | 73 | |
| | 74 | def test_column_merge(self): |
| | 75 | # XXX not supported yet |
| | 76 | #self.new_cursor.execute("CREATE TABLE a (b INTEGER, " |
| | 77 | # "c INTEGER CONSTRAINT fk REFERENCES d(id))") |
| | 78 | |
| | 79 | self._verify_merge("a", |
| | 80 | "b INTEGER, c INTEGER", |
| | 81 | "b INTEGER") |
| | 82 | |
| | 83 | self._verify_merge( |
| | 84 | "b INTEGER, c INTEGER NOT NULL DEFAULT 3", |
| | 85 | "b INTEGER") |
| | 86 | |
| | 87 | self._verify_merge_fails(sqlite.OperationalError, |
| | 88 | "b INTEGER, c INTEGER NOT NULL", |
| | 89 | "b INTEGER") |
| | 90 | |
| | 91 | self._verify_merge_fails(Exception, |
| | 92 | "b INTEGER, c INTEGERY PRIMARY KEY", |
| | 93 | "b INTEGER") |