summaryrefslogtreecommitdiff
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-01-10 11:13:34 -0500
committerR David Murray <rdmurray@bitdance.com>2013-01-10 11:13:34 -0500
commitb434554512d52137b70f92ea87b01534de7d9217 (patch)
tree2a233823d3bafaa2ec84c7792f42591901a048cf /Lib/sqlite3
parente46101e95dfb10d9ad2873e2db97555844da1dff (diff)
parent8e596eba45382eff295a180b94de7e0184ff5fc2 (diff)
downloadcpython-b434554512d52137b70f92ea87b01534de7d9217.tar.gz
merge #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.
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/dump.py3
-rw-r--r--Lib/sqlite3/test/dump.py21
2 files changed, 23 insertions, 1 deletions
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py
index da6be68663..de9c368be3 100644
--- a/Lib/sqlite3/dump.py
+++ b/Lib/sqlite3/dump.py
@@ -25,9 +25,10 @@ def _iterdump(connection):
FROM "sqlite_master"
WHERE "sql" NOT NULL AND
"type" == 'table'
+ ORDER BY "name"
"""
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':
yield('DELETE FROM "sqlite_sequence";')
elif table_name == 'sqlite_stat1':
diff --git a/Lib/sqlite3/test/dump.py b/Lib/sqlite3/test/dump.py
index b200333afa..a1f45a46dc 100644
--- a/Lib/sqlite3/test/dump.py
+++ b/Lib/sqlite3/test/dump.py
@@ -49,6 +49,27 @@ class DumpTests(unittest.TestCase):
[self.assertEqual(expected_sqls[i], actual_sqls[i])
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():
return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))