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

Commit34930cb

Browse files
Compat with other backends: silently coerce keys to bytes
1 parentb1b9a9b commit34930cb

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

‎Lib/dbm/sqlite3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
)
1313
"""
1414
GET_SIZE="SELECT COUNT (key) FROM Dict"
15-
LOOKUP_KEY="SELECT value FROM Dict WHERE key =?"
15+
LOOKUP_KEY="SELECT value FROM Dict WHERE key =CAST(? AS BLOB)"
1616
STORE_KV="REPLACE INTO Dict (key, value) VALUES (CAST(? AS BLOB), CAST(? AS BLOB))"
17-
DELETE_KEY="DELETE FROM Dict WHERE key =?"
17+
DELETE_KEY="DELETE FROM Dict WHERE key =CAST(? AS BLOB)"
1818
ITER_KEYS="SELECT key FROM Dict"
1919

2020

‎Lib/test/test_dbm_sqlite3.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class DataTypes(_SQLiteDbmTests):
213213
(42,b"42"),
214214
(3.14,b"3.14"),
215215
("string",b"string"),
216+
(b"bytes",b"bytes"),
216217
)
217218

218219
defsetUp(self):
@@ -234,10 +235,15 @@ def test_datatypes_keys(self):
234235
withself.subTest(raw=raw,coerced=coerced):
235236
self.db[raw]="value"
236237
self.assertEqual(self.db[coerced],b"value")
237-
withself.assertRaises(KeyError):
238-
self.db[raw]
239-
withself.assertRaises(KeyError):
240-
delself.db[raw]
238+
# Raw keys are silently coerced to bytes.
239+
self.assertEqual(self.db[raw],b"value")
240+
delself.db[raw]
241+
242+
deftest_datatypes_replace_coerced(self):
243+
self.db["10"]="value"
244+
self.db[b"10"]="value"
245+
self.db[10]="value"
246+
self.assertEqual(self.db.keys(), [b"10"])
241247

242248

243249
classCorruptDatabase(_SQLiteDbmTests):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp