Mercurial > cpython-lru_cache-weakref
diff Lib/sqlite3/test/dump.py @ 81370:bb4e4f0cec2e 2.7
#15545: sort iterdump via SQL instead of in python code
Although there is not a regression in Python2, we make the same update here to
keep the code bases in sync.
(The fix for issue 9750 introduced a regression in Python 3 by sorting the row
objects returned by fetchall. But if a row_factory such as sqlite3.Row is
used, the rows may not be sortable (in Python3), which leads to an exception.
The sorting is still a nice idea, so the patch moves the sort into the sql.)
Fix and test by Peter Otten.
| author | R David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 10 Jan 2013 11:30:51 -0500 |
| parents | 60aa7dacb605 |
| children | 2a417ad8bfbf |
line wrap: on
line diff
--- a/Lib/sqlite3/test/dump.py Wed Jan 09 22:04:35 2013 -0800 +++ b/Lib/sqlite3/test/dump.py Thu Jan 10 11:30:51 2013 -0500 @@ -49,6 +49,27 @@ [self.assertEqual(expected_sqls[i], actual_sqls[i]) for i in xrange(len(expected_sqls))] + def CheckUnorderableRow(self): + # iterdump() should be able to cope with unorderable row types (issue #15545) + class UnorderableRow: + def __init__(self, cursor, row): + self.row = row + def __getitem__(self, index): + return self.row[index] + self.cx.row_factory = UnorderableRow + CREATE_ALPHA = """CREATE TABLE "alpha" ("one");""" + CREATE_BETA = """CREATE TABLE "beta" ("two");""" + expected = [ + "BEGIN TRANSACTION;", + CREATE_ALPHA, + CREATE_BETA, + "COMMIT;" + ] + self.cu.execute(CREATE_BETA) + self.cu.execute(CREATE_ALPHA) + got = list(self.cx.iterdump()) + self.assertEqual(expected, got) + def suite(): return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))
