mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
A cleaner fix than the one committed last night. Generate random rowids that
do not contain null bytes.
This commit is contained in:
parent
f8a2a0b5a9
commit
3ef21cb7c6
1 changed files with 6 additions and 5 deletions
|
@ -360,12 +360,13 @@ class bsdTableDB :
|
|||
unique = 0
|
||||
while not unique:
|
||||
# Generate a random 64-bit row ID string
|
||||
# (note: this code has <56 bits of randomness
|
||||
# (note: this code has <64 bits of randomness
|
||||
# but it's plenty for our database id needs!)
|
||||
# The | 0x01010101 is to ensure no null bytes are in the value
|
||||
newid = struct.pack('ll',
|
||||
random.randint(0, 2147483647) | 0x01010101,
|
||||
random.randint(0, 2147483647) | 0x01010101)
|
||||
# We must ensure that no null bytes are in the id value.
|
||||
blist = []
|
||||
for x in xrange(_rowid_str_len):
|
||||
blist.append(random.randint(1,255))
|
||||
newid = struct.pack('B'*_rowid_str_len, *blist)
|
||||
|
||||
# Guarantee uniqueness by adding this key to the database
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue