def getNextSeq(self, db): c = db.cursor() q_v = c.last() if q_v: q,v = q_v return q+1 else: return 1
def getNextSeq(self, db): c = db.cursor() q_v = c.last() if q_v: q, v = q_v return q + 1 else: return 1
def report(self, db): print "=" * 80 c = db.cursor() while True: d = c.next() if not d: break #print d print d
def report(self, db): print "="* 80 c = db.cursor() while True: d = c.next() if not d: break #print d print d
def iter_range(db, key_prefix): cursor = db.cursor() try: data = cursor.set_range(key_prefix) while data and data[0].startswith(key_prefix): yield data data = cursor.next() finally: cursor.close()
def iter_db(db): cursor = db.cursor() try: data = cursor.first() while data: yield data data = cursor.next() finally: cursor.close()
def deleteLastNFromDb(self, n, db): for _ in range(n): c = db.cursor() s_d = c.last() if not s_d: # No data! Och well break seq, data = s_d print "Deleting %s %s" % (seq, data) del db[seq] db.sync()
def test6(): print "start a read-only cursor notxn, then start a txn" cur1 = db.cursor(None, cur_flags_notxn) print "read data using notxn cursor" print_records(db, None, cur1) print "create txn" txn1 = env.txn_begin(None, txn_flags) print "create txn cursor" cur2 = db.cursor(txn1, cur_flags) print "position cursor" cur2.last() print "put data using cursor" cur2.put("txnkey", "txndata", bsddb.db.DB_CURRENT) print "read data using txn cursor" print_records(db, None, cur2) print "modify data inside the txn" print "read data using notxn cursor" print_records(db, None, cur1) print "read data using txn cursor" print_records(db, None, cur2) cur1.close() cur2.close() txn1.abort()
def print_records(db, txn=None): flags = cur_flags if txn: print "records for txn", txn else: print "no txn records" cur = db.cursor(txn, flags) rec = cur.first() while rec: try: print "\tkey=%s val=%s" % rec rec = cur.next() except Exception, ex: print "caught", ex break
def print_records(db, txn=None, cur=None): flags = cur_flags if txn: print "records for txn", txn else: print "no txn records" closecur = False if not cur: cur = db.cursor(txn, flags) closecur = True rec = cur.first() while rec: try: print "\tkey=%s val=%s" % rec print "\textra=%s" % str(cur.get(bsddb.db.DB_GET_RECNO)) rec = cur.next() except Exception, ex: print "caught", ex break
#seq_flags = bsddb.db.DB_CREATE|bsddb.db.DB_THREAD #uidseq = bsddb.db.DBSequence(db) #uidseq.open("uidnumber", None, seq_flags) #usnseq = bsddb.db.DBSequence(db) #usnseq.open("usn", None, seq_flags) def loaddb(): for ii in xrange(0,10): db.put("key" + str(ii), "data" + str(ii)) flags = bsddb.db.DB_NODUPDATA # flags = bsddb.db.DB_NOOVERWRITE for ii in xrange(0,10): db.put("multikey", "multidata" + str(ii), None, flags) loaddb() cur = db.cursor(None, cur_flags_notxn) print_records(db, None, cur) def test1(): print "test 1 - abort child txn but commit parent txn" print_records(db) print "create parent txn" partxn = env.txn_begin(None, txn_flags) print "do a write inside the parent before the child" db.put("parent before key", "parent before data", partxn) print_records(db, partxn) uidnum = uidseq.get(1, partxn) print "uidnumber is", uidnum print "create child transaction" chitxn = env.txn_begin(partxn, txn_flags)