File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1212 )
1313"""
1414GET_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) "
1616STORE_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) "
1818ITER_KEYS = "SELECT key FROM Dict"
1919
2020
Original file line number Diff line number Diff 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 def setUp (self ):
@@ -234,10 +235,15 @@ def test_datatypes_keys(self):
234235 with self .subTest (raw = raw , coerced = coerced ):
235236 self .db [raw ] = "value"
236237 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" ])
241247
242248
243249class CorruptDatabase (_SQLiteDbmTests ):
You can’t perform that action at this time.
0 commit comments