Example #1
0
    def foreach(self, proc, op):
        """Process each record atomically of a B+ tree database
        object."""
        def proc_wraper(c_key, c_key_len, c_value, c_value_len, op):
            key = util.deserialize(ctypes.cast(c_key, ctypes.c_void_p),
                                   c_key_len, str)
            value = util.deserialize(ctypes.cast(c_value, ctypes.c_void_p),
                                     c_value_len, str)
            return proc(key, value, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.bdb_foreach(self.db, tc.TCITER(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.bdb_errmsg(tc.bdb_ecode(self.db)))
        return result
Example #2
0
    def foreach(self, proc, op, key_type=None, value_type=None):
        """Process each record atomically of an abstract database
        object."""
        def proc_wraper(c_key, c_key_len, c_value, c_value_len, op):
            key = util.deserialize(ctypes.cast(c_key, ctypes.c_void_p),
                                   c_key_len, key_type)
            value = util.deserialize(ctypes.cast(c_value, ctypes.c_void_p),
                                     c_value_len, value_type)
            return proc(key, value, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.adb_foreach(self.db, tc.TCITER(proc_wraper), op)
        if not result:
            self._raise('Error processing each record atomically of an ' \
                            'abstract database object.')
        return result