How to use the bsddb3.db.DB_CREATE function in bsddb3

To help you get started, we’ve selected a few bsddb3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biopython / biopython / Bio / Mindy / BerkeleyDB.py View on Github external
def create(dbname, primary_namespace, secondary_namespaces,
           formatname = "unknown"):
    os.mkdir(dbname)
    config_filename = os.path.join(dbname, "config.dat")
    BaseDB.write_config(config_filename = config_filename,
                        index_type = INDEX_TYPE,
                        primary_namespace = primary_namespace,
                        secondary_namespaces = secondary_namespaces,
                        fileid_info = {},
                        formatname = formatname
                        )

    dbenv = db.DBEnv(0)
    envflags = db.DB_THREAD | db.DB_INIT_MPOOL
    dbenv.open(dbname, envflags | db.DB_CREATE)

    primary_table = db.DB(dbenv)
    primary_table.open("key_%s" % (primary_namespace,), None,
                       db.DB_BTREE, db.DB_CREATE, 0660)

    secondary_tables = {}
    for namespace in secondary_namespaces:
        x = db.DB(dbenv)
        x.open("id_%s" % (namespace,), None, db.DB_BTREE, db.DB_CREATE, 0)
        secondary_tables[namespace] = x

    for x in secondary_tables.values():
        x.close()
    primary_table.close()
    dbenv.close()
github ospaceteam / outerspace / server / lib / ige / BSDDBSyncDatabase.py View on Github external
self.dbName = dbName
        self.nextID = 10000
        self.cacheSize = cache
        #
        try:
            os.makedirs(directory)
        except OSError:
            pass
        # create db env when needed
        if not dbEnv:
            log.debug("BSDSDB - creating environment")
            dbEnv = db.DBEnv()
            dbEnv.set_lg_max(16 * 1024 * 1024)
            dbEnv.set_cachesize(0, 10 * 1024 * 1024, 0)
            dbEnv.set_get_returns_none(0)
            dbEnv.open(directory, db.DB_CREATE | db.DB_INIT_MPOOL)
            log.debug("BSDSDB - environment created")
        self.db = db.DB(dbEnv)
        if not pagesize:
            self.db.set_pagesize(8192)
        else:
            self.db.set_pagesize(pagesize)
        # open
        self.db.open(dbName, dbtype = db.DB_BTREE, flags = db.DB_CREATE)
        dbOpened += 1
        # cache
        self.cache = {}
        self.cacheLinks = {
            "__first__": [None, "__last__"],
            "__last__": ["__first__", None],
        }
        # stats
github GNOME / pybliographer / Pyblio / db3base.py View on Github external
def db3open (self, filename, filetype, mode=0666,
                 flags=0, dbenv=None, dbtype=db.DB):
        name = os.path.join(self.path, filename)
        #print '**', filename, '**', self.path, '**', name
        dbfile = dbtype(dbenv)
        dbfile.open(name, filetype, mode=mode,
                    flags=flags | db.DB_CREATE)
        return dbfile
github PyTables / PyTables / bench / bsddb-table-bench.py View on Github external
def createFile(filename, totalrows, recsize, verbose):

    # Open a 'n'ew file
    dd = db.DB()
    if recsize == "big":
        isrec = Description(Big)
    elif recsize == "medium":
        isrec = Medium()
    else:
        isrec = Description(Small)
    # dd.set_re_len(struct.calcsize(isrec._v_fmt))  # fixed length records
    dd.open(filename, db.DB_RECNO, db.DB_CREATE | db.DB_TRUNCATE)

    rowswritten = 0
    # Get the record object associated with the new table
    if recsize == "big":
        isrec = Big()
        arr = np.array(np.arange(32), type=np.Float64)
        arr2 = np.array(np.arange(32), type=np.Float64)
    elif recsize == "medium":
        isrec = Medium()
        arr = np.array(np.arange(2), type=np.Float64)
    else:
        isrec = Small()
    # print d
    # Fill the table
    if recsize == "big" or recsize == "medium":
        d = {"name": " ",
github RDFLib / rdflib / rdflib / store / backends / SleepyCatBacked.py View on Github external
self.__cpos = db.DB(env)
        self.__cpos.set_flags(dbsetflags)
        self.__cpos.open("cpos", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__cosp = db.DB(env)
        self.__cosp.set_flags(dbsetflags)
        self.__cosp.open("cosp", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__i2k = db.DB(env)
        self.__i2k.set_flags(dbsetflags)
        self.__i2k.open("i2k", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__k2i = db.DB(env)
        self.__k2i.set_flags(dbsetflags)
        self.__k2i.open("k2i", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
        self.next = self.__k2i.stat()["nkeys"]
github RDFLib / rdflib / rdflib / backends / SleepyCat.py View on Github external
dbopenflags = db.DB_THREAD
        
        dbmode = 0660
        dbsetflags   = 0

        # create and open the DBs
        self.__contexts = db.DB(env)
        self.__contexts.set_flags(dbsetflags)
        self.__contexts.open("contexts", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
        self.__spo = db.DB(env)
        self.__spo.set_flags(dbsetflags)
        self.__spo.open("spo", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__pos = db.DB(env)
        self.__pos.set_flags(dbsetflags)
        self.__pos.open("pos", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__osp = db.DB(env)
        self.__osp.set_flags(dbsetflags)
        self.__osp.open("osp", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__cspo = db.DB(env)
        self.__cspo.set_flags(dbsetflags)
        self.__cspo.open("cspo", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__cpos = db.DB(env)
        self.__cpos.set_flags(dbsetflags)
        self.__cpos.open("cpos", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__cosp = db.DB(env)
        self.__cosp.set_flags(dbsetflags)
        self.__cosp.open("cosp", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
github connectIOT / iottoolkit / iottoolkit / rdflib3 / plugins / sleepycat.py View on Github external
# auto-commit ensures that the open-call commits when transactions are enabled
        dbopenflags = db.DB_THREAD 
        if self.transaction_aware == True:
            dbopenflags |= db.DB_AUTO_COMMIT

        dbmode = 0660
        dbsetflags   = 0

        # create and open the DBs
        self.__indicies = [None,] * 3
        self.__indicies_info = [None,] * 3
        for i in xrange(0, 3):
            index_name = to_key_func(i)((b("s"), b("p"), b("o")), b("c")).decode()
            index = db.DB(db_env)
            index.set_flags(dbsetflags)
            index.open(index_name, dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
            self.__indicies[i] = index
            self.__indicies_info[i] = (index, to_key_func(i), from_key_func(i))

        lookup = {}
        for i in xrange(0, 8):
            results = []
            for start in xrange(0, 3):
                score = 1
                len = 0
                for j in xrange(start, start+3):
                    if i & (1<<(j%3)):
                        score = score << 1
                        len += 1
                    else:
                        break
                tie_break = 2-start
github examachine / pisi / pisi / db / lockeddbshelve.py View on Github external
    def open(self, filename, dbname, filetype, flags=db.DB_CREATE, mode=0644):
        self.filename = filename        
        self.closed = False
        if type(flags) == type(''):
            sflag = flags
            if sflag == 'r':
                flags = db.DB_RDONLY
            elif sflag == 'rw':
                flags = 0
            elif sflag == 'w':
                flags =  db.DB_CREATE
            elif sflag == 'c':
                flags =  db.DB_CREATE
            elif sflag == 'n':
                flags = db.DB_TRUNCATE | db.DB_CREATE
            else:
                raise Error, _("Flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags")
github cheshire3 / cheshire3 / cheshire3 / indexStore.py View on Github external
def _get_internalId(self, session, rec):
        if rec.recordStore in self.identifierMapCxn:
            cxn = self.identifierMapCxn[rec.recordStore]
        else:
            fn = "recordIdentifiers_{0}_{1}.bdb".format(self.id,
                                                        rec.recordStore)
            dfp = self.get_path(session, "defaultPath")
            dbp = os.path.join(dfp, fn)
            if not os.path.exists(dbp):
                cxn = bdb.db.DB()
                cxn.open(dbp, dbtype=bdb.db.DB_BTREE,
                         flags=bdb.db.DB_CREATE, mode=0660)
                cxn.close()
            cxn = bdb.db.DB()
            if session.environment == "apache":
                cxn.open(dbp, flags=bdb.db.DB_NOMMAP)
            else:
                cxn.open(dbp)
            self.identifierMapCxn[rec.recordStore] = cxn
        # Now we have cxn, check it rec exists
        recid = rec.id
        if type(recid) == unicode:
            try:
                recid = rec.id.encode('utf-8')
            except:
                recid = rec.id.encode('utf-16')
        try:
            data = cxn.get(recid)