memdb conflict check, thanks Luca

This commit is contained in:
Massimo
2013-11-14 13:29:46 -06:00
parent 948e0b1f43
commit 07f0cdadcd
2 changed files with 9 additions and 6 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.7.4-stable+timestamp.2013.11.13.14.06.31
Version 2.7.4-stable+timestamp.2013.11.14.13.28.53
+8 -5
View File
@@ -253,12 +253,15 @@ class Table(DALStorage):
self._db(self.id > 0).delete()
def insert(self, **fields):
id = self._create_id()
if self.update(id, **fields):
return long(id)
def insert(self, **fields):
# Checks 3 times that the id is new. 3 times is enough!
for i in range(3):
id = self._create_id()
if self.get(id) is None and self.update(id, **fields):
return long(id)
else:
return None
raise RuntimeError("Too many ID conflicts")
def get(self, id):
val = self._tableobj.get(self._id_to_key(id))