[Python-checkins] cpython (merge 3.3 -> default): merge #15545: fix sqlite3.iterdump regression on unsortable row_factory objects.
r.david.murray
python-checkins at python.org
Thu Jan 10 17:31:35 CET 2013
http://hg.python.org/cpython/rev/7a62b5ee32ec
changeset: 81369:7a62b5ee32ec
parent: 81366:6da90e44c6a0
parent: 81368:6a85894c428f
user: R David Murray <rdmurray at bitdance.com>
date: Thu Jan 10 11:15:57 2013 -0500
summary:
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.
files:
Lib/sqlite3/dump.py | 3 ++-
Lib/sqlite3/test/dump.py | 21 +++++++++++++++++++++
Misc/NEWS | 4 ++++
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py
--- a/Lib/sqlite3/dump.py
+++ b/Lib/sqlite3/dump.py
@@ -25,9 +25,10 @@
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
--- a/Lib/sqlite3/test/dump.py
+++ b/Lib/sqlite3/test/dump.py
@@ -49,6 +49,27 @@
[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"))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -212,6 +212,10 @@
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 #16876: Optimize epoll.poll() by keeping a per-instance epoll events
buffer instead of allocating a new one at each poll().
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list