Ejemplo n.º 1
0
 def setdfunit(self, dfunit=0):
     """Set the unit step number of auto defragmentation of a B+
     tree database object."""
     result = tc.bdb_setdfunit(self.db, dfunit)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 2
0
 def setdfunit(self, dfunit=0):
     """Set the unit step number of auto defragmentation of a hash
     database object."""
     result = tc.hdb_setdfunit(self.db, dfunit)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 3
0
 def setinvcache(self, iccmax, iccsync):
     """Set the parameters of the inverted cache of a table
     database object."""
     result = tc.tdb_setinvcache(self.db, iccmax, iccsync)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 4
0
 def searchout_non_atomic(self):
     """Remove each record corresponding to a query object with
     non-atomic fashion."""
     result = tc.tdb_qrysearchout2(self.qry)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 5
0
 def out(self, key, as_raw=False):
     """Remove a record of a table database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_out(self.db, c_key, c_key_len)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 6
0
 def setxmsiz(self, xmsiz=0):
     """Set the size of the extra mapped memory of a hash database
     object."""
     result = tc.hdb_setxmsiz(self.db, xmsiz)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 7
0
 def fsiz(self):
     """Get the size of the database file of a table database
     object."""
     result = tc.tdb_fsiz(self.db)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 8
0
 def sync(self):
     """Synchronize updated contents of a table database object with
     the file and the device."""
     result = tc.tdb_sync(self.db)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 9
0
 def out(self, key, as_raw=False):
     """Remove a record of a table database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_out(self.db, c_key, c_key_len)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 10
0
 def defrag(self, step):
     """Perform dynamic defragmentation of a table database
     object."""
     result = tc.tdb_defrag(self.db, step)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 11
0
 def defrag(self, step):
     """Perform dynamic defragmentation of a table database
     object."""
     result = tc.tdb_defrag(self.db, step)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 12
0
 def memsync(self, phys):
     """Synchronize updating contents on memory of a table database
     object."""
     result = tc.tdb_memsync(self.db, phys)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 13
0
 def tune(self, width=0, limsiz=0):
     """Set the tuning parameters of a fixed-length database
     object."""
     result = tc.fdb_tune(self.db, width, limsiz)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 14
0
 def setuidseed(self, seed):
     """Set the seed of unique ID unumbers of a table database
     object."""
     result = tc.tdb_setuidseed(self.db, seed)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 15
0
 def setuidseed(self, seed):
     """Set the seed of unique ID unumbers of a table database
     object."""
     result = tc.tdb_setuidseed(self.db, seed)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 16
0
 def setinvcache(self, iccmax, iccsync):
     """Set the parameters of the inverted cache of a table
     database object."""
     result = tc.tdb_setinvcache(self.db, iccmax, iccsync)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 17
0
 def memsync(self, phys):
     """Synchronize updating contents on memory of a table database
     object."""
     result = tc.tdb_memsync(self.db, phys)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 18
0
 def fsiz(self):
     """Get the size of the database file of a table database
     object."""
     result = tc.tdb_fsiz(self.db)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 19
0
 def setxmsiz(self, xmsiz=0):
     """Set the size of the extra mapped memory of a B+ tree
     database object."""
     result = tc.bdb_setxmsiz(self.db, xmsiz)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 20
0
 def searchout_non_atomic(self):
     """Remove each record corresponding to a query object with
     non-atomic fashion."""
     result = tc.tdb_qrysearchout2(self.qry)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 21
0
 def sync(self):
     """Synchronize updated contents of a table database object with
     the file and the device."""
     result = tc.tdb_sync(self.db)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 22
0
 def vsiz(self, key, as_raw=False):
     """Get the size of the value of a Python object in a table
     database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_vsiz(self.db, c_key, c_key_len)
     if result == -1:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 23
0
 def vsiz(self, key, as_raw=False):
     """Get the size of the value of a Python object in a table
     database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_vsiz(self.db, c_key, c_key_len)
     if result == -1:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 24
0
 def putcat(self, key, cols, raw_key=False, raw_cols=False):
     """Concatenate columns of the existing record in a table
     database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = util.serialize_tcmap(cols, raw_cols)
     result = tc.tdb_putcat(self.db, c_key, c_key_len, cols_tcmap)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 25
0
 def add_float(self, key, num, as_raw=False):
     """Add a real number to a column of a record in a table
     database object."""
     assert isinstance(num, float), 'Value is not a float'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_adddouble(self.db, c_key, c_key_len, num)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 26
0
 def add_float(self, key, num, as_raw=False):
     """Add a real number to a column of a record in a table
     database object."""
     assert isinstance(num, float), 'Value is not a float'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.tdb_adddouble(self.db, c_key, c_key_len, num)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 27
0
 def fwmkeys(self, prefix, as_raw=True):
     """Get forward matching primary keys in a table database
     object."""
     (c_prefix, c_prefix_len) = util.serialize(prefix, as_raw)
     tclist_objs = tc.tdb_fwmkeys(self.db, c_prefix, c_prefix_len)
     if not tclist_objs:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     as_type = util.get_type(prefix, as_raw)
     return util.deserialize_tclist(tclist_objs, as_type)
Ejemplo n.º 28
0
 def fwmkeys(self, prefix, as_raw=True):
     """Get forward matching primary keys in a table database
     object."""
     (c_prefix, c_prefix_len) = util.serialize(prefix, as_raw)
     tclist_objs = tc.tdb_fwmkeys(self.db, c_prefix, c_prefix_len)
     if not tclist_objs:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     as_type = util.get_type(prefix, as_raw)
     return util.deserialize_tclist(tclist_objs, as_type)
Ejemplo n.º 29
0
 def put(self, key, cols, raw_key=False, raw_cols=False):
     """Store a record into a table database object."""
     assert isinstance(cols, dict)
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = util.serialize_tcmap(cols, raw_cols)
     result = tc.tdb_put(self.db, c_key, c_key_len, cols_tcmap)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 30
0
 def put(self, key, cols, raw_key=False, raw_cols=False):
     """Store a record into a table database object."""
     assert isinstance(cols, dict)
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = util.serialize_tcmap(cols, raw_cols)
     result = tc.tdb_put(self.db, c_key, c_key_len, cols_tcmap)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 31
0
 def putcat(self, key, cols, raw_key=False, raw_cols=False):
     """Concatenate columns of the existing record in a table
     database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     cols_tcmap = util.serialize_tcmap(cols, raw_cols)
     result = tc.tdb_putcat(self.db, c_key, c_key_len, cols_tcmap)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 32
0
 def itervalues(self, schema=None):
     """Iterate for every value in a table database object."""
     if not tc.tdb_iterinit(self.db):
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     while True:
         cols_tcmap = tc.tdb_iternext3(self.db)
         if not cols_tcmap:
             break
         cols = util.deserialize_tcmap(cols_tcmap, schema)
         yield cols
Ejemplo n.º 33
0
 def iterkeys(self, as_type=None):
     """Iterate for every key in a table database object."""
     if not tc.tdb_iterinit(self.db):
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.tdb_iternext(self.db)
         if not c_key:
             break
         key = util.deserialize(c_key, c_key_len, as_type)
         yield key
Ejemplo n.º 34
0
 def iterkeys(self, as_type=None):
     """Iterate for every key in a table database object."""
     if not tc.tdb_iterinit(self.db):
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.tdb_iternext(self.db)
         if not c_key:
             break
         key = util.deserialize(c_key, c_key_len, as_type)
         yield key
Ejemplo n.º 35
0
 def itervalues(self, schema=None):
     """Iterate for every value in a table database object."""
     if not tc.tdb_iterinit(self.db):
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     while True:
         cols_tcmap = tc.tdb_iternext3(self.db)
         if not cols_tcmap:
             break
         cols = util.deserialize_tcmap(cols_tcmap, schema)
         yield cols
Ejemplo n.º 36
0
    def open(self, path, omode=OWRITER|OCREAT, bnum=0, apow=-1, fpow=-1,
             opts=0, rcnum=0, lcnum=0, ncnum=0, xmsiz=0, dfunit=0):
        """Open a database file and connect a table database object."""
        self.setcache(rcnum, lcnum, ncnum)
        self.setxmsiz(xmsiz)
        self.setdfunit(dfunit)
        self.tune(bnum, apow, fpow, opts)

        if not tc.tdb_open(self.db, path, omode):
            raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
Ejemplo n.º 37
0
 def optimize(self, bnum=None, apow=None, fpow=None, opts=None):
     """Optimize the file of a table database object."""
     kwargs = dict([
         x for x in (('bnum', bnum), ('apow', apow), ('fpow', fpow),
                     ('opts', opts)) if x[1]
     ])
     result = tc.tdb_optimize(self.db, **kwargs)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 38
0
 def optimize(self, bnum=None, apow=None, fpow=None, opts=None):
     """Optimize the file of a table database object."""
     kwargs = dict([x for x in (('bnum', bnum),
                                ('apow', apow),
                                ('fpow', fpow),
                                ('opts', opts)) if x[1]])
     result = tc.tdb_optimize(self.db, **kwargs)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 39
0
 def iteritems(self, key_type=None, schema=None):
     """Iterate for every key / value in a table database object."""
     if not tc.tdb_iterinit(self.db):
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.tdb_iternext(self.db)
         if not c_key:
             break
         cols_tcmap = tc.tdb_get(self.db, c_key, c_key_len)
         key = util.deserialize(c_key, c_key_len, key_type)
         cols = util.deserialize_tcmap(cols_tcmap, schema)
         yield (key, cols)
Ejemplo n.º 40
0
    def proc(self, proc, op):
        """Process each record corresponding to a query object."""
        def proc_wraper(c_pkey, c_pkey_len, c_cols, op):
            pkey = util.deserialize(ctypes.cast(c_pkey, ctypes.c_void_p),
                                    c_pkey_len, as_type=int)
            cols = util.deserialize_tcmap(c_cols)
            return proc(pkey, cols, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.tdb_qryproc(self.qry, tc.TDBQRYPROC(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
        return result
Ejemplo n.º 41
0
 def iteritems(self, key_type=None, schema=None):
     """Iterate for every key / value in a table database object."""
     if not tc.tdb_iterinit(self.db):
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.tdb_iternext(self.db)
         if not c_key:
             break
         cols_tcmap = tc.tdb_get(self.db, c_key, c_key_len)
         key = util.deserialize(c_key, c_key_len, key_type)
         cols = util.deserialize_tcmap(cols_tcmap, schema)
         yield (key, cols)
Ejemplo n.º 42
0
    def proc(self, proc, op):
        """Process each record corresponding to a query object."""
        def proc_wraper(c_pkey, c_pkey_len, c_cols, op):
            pkey = util.deserialize(ctypes.cast(c_pkey, ctypes.c_void_p),
                                    c_pkey_len,
                                    as_type=int)
            cols = util.deserialize_tcmap(c_cols)
            return proc(pkey, cols, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.tdb_qryproc(self.qry, tc.TDBQRYPROC(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
        return result
Ejemplo n.º 43
0
    def foreach(self, proc, op, key_type=None, schema=None):
        """Process each record atomically of a table database
        object."""
        def proc_wraper(c_key, c_key_len, c_cols, c_cols_len, op):
            key = util.deserialize(ctypes.cast(c_key, ctypes.c_void_p),
                                   c_key_len, key_type)
            cols = util.deserialize(ctypes.cast(c_cols, ctypes.c_void_p),
                                    c_cols_len, str)
            return proc(key, cols, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.tdb_foreach(self.db, tc.TCITER(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
        return result
Ejemplo n.º 44
0
    def foreach(self, proc, op, key_type=None, schema=None):
        """Process each record atomically of a table database
        object."""
        def proc_wraper(c_key, c_key_len, c_cols, c_cols_len, op):
            key = util.deserialize(ctypes.cast(c_key, ctypes.c_void_p),
                                   c_key_len, key_type)
            cols = util.deserialize(ctypes.cast(c_cols, ctypes.c_void_p),
                                    c_cols_len, str)
            return proc(key, cols, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.tdb_foreach(self.db, tc.TCITER(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
        return result
Ejemplo n.º 45
0
 def _raise(self, msg=None):
     """Raise an exception based on the internal database object."""
     mode = self.omode()
     if mode == OMDB:
         msg = 'Error in hash memory abstract database object.'
     elif mode == ONDB:
         msg = 'Error in B+ tree memory abstract database object.'
     elif mode == OHDB:
         msg = tc.hdb_errmsg(tc.hdb_ecode(self.reveal()))
     elif mode == OBDB:
         msg = tc.bdb_errmsg(tc.bdb_ecode(self.reveal()))
     elif mode == OFDB:
         msg = tc.fdb_errmsg(tc.fdb_ecode(self.reveal()))
     elif mode == OTDB:
         msg = tc.tdb_errmsg(tc.tdb_ecode(self.reveal()))
     raise tc.TCException(msg)
Ejemplo n.º 46
0
 def _raise(self, msg=None):
     """Raise an exception based on the internal database object."""
     mode = self.omode()
     if mode == OMDB:
         msg = 'Error in hash memory abstract database object.'
     elif mode == ONDB:
         msg = 'Error in B+ tree memory abstract database object.'
     elif mode == OHDB:
         msg = tc.hdb_errmsg(tc.hdb_ecode(self.reveal()))
     elif mode == OBDB:
         msg = tc.bdb_errmsg(tc.bdb_ecode(self.reveal()))
     elif mode == OFDB:
         msg = tc.fdb_errmsg(tc.fdb_ecode(self.reveal()))
     elif mode == OTDB:
         msg = tc.tdb_errmsg(tc.tdb_ecode(self.reveal()))
     raise tc.TCException(msg)
Ejemplo n.º 47
0
    def open(self,
             path,
             omode=OWRITER | OCREAT,
             bnum=0,
             apow=-1,
             fpow=-1,
             opts=0,
             rcnum=0,
             lcnum=0,
             ncnum=0,
             xmsiz=0,
             dfunit=0):
        """Open a database file and connect a table database object."""
        self.setcache(rcnum, lcnum, ncnum)
        self.setxmsiz(xmsiz)
        self.setdfunit(dfunit)
        self.tune(bnum, apow, fpow, opts)

        if not tc.tdb_open(self.db, path, omode):
            raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
Ejemplo n.º 48
0
 def genuid(self):
     """Generate a unique ID number of a table database object."""
     result = tc.tdb_genuid(self.db)
     if result == -1:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 49
0
 def setcache(self, rcnum=0):
     """Set the caching parameters of a hash database object."""
     result = tc.hdb_setcache(self.db, rcnum)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 50
0
 def path(self):
     """Get the file path of a table database object."""
     result = tc.tdb_path(self.db)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 51
0
 def path(self):
     """Get the file path of a table database object."""
     result = tc.tdb_path(self.db)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 52
0
 def tune(self, bnum=0, apow=-1, fpow=-1, opts=0):
     """Set the tuning parameters of a hash database object."""
     result = tc.hdb_tune(self.db, bnum, apow, fpow, opts)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 53
0
 def tune(self, lmemb=0, nmemb=0, bnum=0, apow=-1, fpow=-1, opts=0):
     """Set the tuning parameters of a B+ tree database object."""
     result = tc.bdb_tune(self.db, lmemb, nmemb, bnum, apow, fpow, opts)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 54
0
 def strtometasearchtype(self, str_):
     """Convert a string into the meta search type number."""
     result = tc.tdb_strtometasearchtype(str_)
     if result == -1:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 55
0
 def setindex(self, name, type_):
     """Set a column index to a table database object."""
     result = tc.tdb_setindex(self.db, name, type_)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 56
0
 def setcache(self, lcnum=0, ncnum=0):
     """Set the caching parameters of a B+ tree database object."""
     result = tc.bdb_setcache(self.db, lcnum, ncnum)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 57
0
 def setindex(self, name, type_):
     """Set a column index to a table database object."""
     result = tc.tdb_setindex(self.db, name, type_)
     if not result:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 58
0
 def strtometasearchtype(self, str_):
     """Convert a string into the meta search type number."""
     result = tc.tdb_strtometasearchtype(str_)
     if result == -1:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result
Ejemplo n.º 59
0
 def genuid(self):
     """Generate a unique ID number of a table database object."""
     result = tc.tdb_genuid(self.db)
     if result == -1:
         raise tc.TCException(tc.tdb_errmsg(tc.tdb_ecode(self.db)))
     return result