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

Commit7a843e8

Browse files
erlend-aaslandfelixxmserhiy-storchaka
authored
[3.12]gh-118221: Always use the default row factory in sqlite3.iterdump() (#118223) (#118270)
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 parentfc1732c commit7a843e8

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
@@ -18,6 +18,7 @@ def _iterdump(connection):
1818

1919
writeable_schema=False
2020
cu=connection.cursor()
21+
cu.row_factory=None# Make sure we get predictable results.
2122
yield('BEGIN TRANSACTION;')
2223

2324
# sqlite_master table contains the SQL CREATE statements for the database.

‎Lib/test/test_sqlite3/test_dump.py‎

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

120+
deftest_dump_custom_row_factory(self):
121+
# gh-118221: iterdump should be able to cope with custom row factories.
122+
defdict_factory(cu,row):
123+
fields= [col[0]forcolincu.description]
124+
returndict(zip(fields,row))
125+
126+
self.cx.row_factory=dict_factory
127+
CREATE_TABLE="CREATE TABLE test(t);"
128+
expected= ["BEGIN TRANSACTION;",CREATE_TABLE,"COMMIT;"]
129+
130+
self.cu.execute(CREATE_TABLE)
131+
actual=list(self.cx.iterdump())
132+
self.assertEqual(expected,actual)
133+
self.assertEqual(self.cx.row_factory,dict_factory)
134+
120135
deftest_dump_virtual_tables(self):
121136
# gh-64662
122137
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