#15545: fix sqlite3.iterdump regression on unsortable row_factory objects.
The fix for issue 9750 introduced a regression 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.
This commit is contained in:
parent
78470b4c3a
commit
b52312923b
|
@ -25,9 +25,10 @@ def _iterdump(connection):
|
||||||
FROM "sqlite_master"
|
FROM "sqlite_master"
|
||||||
WHERE "sql" NOT NULL AND
|
WHERE "sql" NOT NULL AND
|
||||||
"type" == 'table'
|
"type" == 'table'
|
||||||
|
ORDER BY "name"
|
||||||
"""
|
"""
|
||||||
schema_res = cu.execute(q)
|
schema_res = cu.execute(q)
|
||||||
for table_name, type, sql in sorted(schema_res.fetchall()):
|
for table_name, type, sql in schema_res.fetchall():
|
||||||
if table_name == 'sqlite_sequence':
|
if table_name == 'sqlite_sequence':
|
||||||
yield('DELETE FROM "sqlite_sequence";')
|
yield('DELETE FROM "sqlite_sequence";')
|
||||||
elif table_name == 'sqlite_stat1':
|
elif table_name == 'sqlite_stat1':
|
||||||
|
|
|
@ -49,6 +49,27 @@ class DumpTests(unittest.TestCase):
|
||||||
[self.assertEqual(expected_sqls[i], actual_sqls[i])
|
[self.assertEqual(expected_sqls[i], actual_sqls[i])
|
||||||
for i in range(len(expected_sqls))]
|
for i in range(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():
|
def suite():
|
||||||
return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))
|
return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #15545: Fix regression in sqlite3's iterdump method where it was
|
||||||
|
failing if the connection used a row factory (such as sqlite3.Row) that
|
||||||
|
produced unsortable objects. (Regression was introduced by fix for 9750).
|
||||||
|
|
||||||
- Issue #16491: IDLE now prints chained exception tracebacks.
|
- Issue #16491: IDLE now prints chained exception tracebacks.
|
||||||
|
|
||||||
- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Patch by
|
- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Patch by
|
||||||
|
|
Loading…
Reference in New Issue