Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite38b43c

Browse files
erlend-aaslandfelixxmserhiy-storchaka
authored
gh-118221: Always use the default row factory in sqlite3.iterdump() (#118223)
sqlite3.iterdump() depends on the row factory returning resulting rowsas tuples; it will fail with custom row factories like for example adict factory.With this commit, we explicitly reset the row factory of the cursor usedby iterdump(), so we always get predictable results. This does notaffect the row factory of the parent connection.Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent796b3fb commite38b43c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

‎Lib/sqlite3/dump.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def _iterdump(connection, *, filter=None):
2626

2727
writeable_schema=False
2828
cu=connection.cursor()
29+
cu.row_factory=None# Make sure we get predictable results.
2930
# Disable foreign key constraints, if there is any foreign key violation.
3031
violations=cu.execute("PRAGMA foreign_key_check").fetchall()
3132
ifviolations:

‎Lib/test/test_sqlite3/test_dump.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,21 @@ def __getitem__(self, index):
190190
got=list(self.cx.iterdump())
191191
self.assertEqual(expected,got)
192192

193+
deftest_dump_custom_row_factory(self):
194+
# gh-118221: iterdump should be able to cope with custom row factories.
195+
defdict_factory(cu,row):
196+
fields= [col[0]forcolincu.description]
197+
returndict(zip(fields,row))
198+
199+
self.cx.row_factory=dict_factory
200+
CREATE_TABLE="CREATE TABLE test(t);"
201+
expected= ["BEGIN TRANSACTION;",CREATE_TABLE,"COMMIT;"]
202+
203+
self.cu.execute(CREATE_TABLE)
204+
actual=list(self.cx.iterdump())
205+
self.assertEqual(expected,actual)
206+
self.assertEqual(self.cx.row_factory,dict_factory)
207+
193208
deftest_dump_virtual_tables(self):
194209
# gh-64662
195210
expected= [
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug where:func:`sqlite3.iterdump` could fail if a custom:attr:`row
2+
factory <sqlite3.Connection.row_factory>` was used. Patch by Erlend Aasland.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp