本文整理匯總了Python中bsddb.db.DB_NOOVERWRITE屬性的典型用法代碼示例。如果您正苦於以下問題:Python db.DB_NOOVERWRITE屬性的具體用法?Python db.DB_NOOVERWRITE怎麽用?Python db.DB_NOOVERWRITE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類bsddb.db
的用法示例。
在下文中一共展示了db.DB_NOOVERWRITE屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __new_rowid
# 需要導入模塊: from bsddb import db [as 別名]
# 或者: from bsddb.db import DB_NOOVERWRITE [as 別名]
def __new_rowid(self, table, txn) :
"""Create a new unique row identifier"""
unique = 0
while not unique:
# Generate a random 64-bit row ID string
# (note: might have <64 bits of true randomness
# but it's plenty for our database id needs!)
blist = []
for x in xrange(_rowid_str_len):
blist.append(random.randint(0,255))
newid = struct.pack('B'*_rowid_str_len, *blist)
if sys.version_info[0] >= 3 :
newid = newid.decode("iso8859-1") # 8 bits
# Guarantee uniqueness by adding this key to the database
try:
self.db.put(_rowid_key(table, newid), None, txn=txn,
flags=db.DB_NOOVERWRITE)
except db.DBKeyExistError:
pass
else:
unique = 1
return newid