File tree 2 files changed +12
-6
lines changed
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 12
12
)
13
13
"""
14
14
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) "
16
16
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) "
18
18
ITER_KEYS = "SELECT key FROM Dict"
19
19
20
20
Original file line number Diff line number Diff line change @@ -213,6 +213,7 @@ class DataTypes(_SQLiteDbmTests):
213
213
(42 , b"42" ),
214
214
(3.14 , b"3.14" ),
215
215
("string" , b"string" ),
216
+ (b"bytes" , b"bytes" ),
216
217
)
217
218
218
219
def setUp (self ):
@@ -234,10 +235,15 @@ def test_datatypes_keys(self):
234
235
with self .subTest (raw = raw , coerced = coerced ):
235
236
self .db [raw ] = "value"
236
237
self .assertEqual (self .db [coerced ], b"value" )
237
- with self .assertRaises (KeyError ):
238
- self .db [raw ]
239
- with self .assertRaises (KeyError ):
240
- del self .db [raw ]
238
+ # Raw keys are silently coerced to bytes.
239
+ self .assertEqual (self .db [raw ], b"value" )
240
+ del self .db [raw ]
241
+
242
+ def test_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" ])
241
247
242
248
243
249
class CorruptDatabase (_SQLiteDbmTests ):
You can’t perform that action at this time.
0 commit comments