Beispiel #1
0
    def get_value(self):
        ''' Get the current value at the iterator

        :returns: The current value at the iterator
        '''
        size = new_native_size()
        pointer = LDB.leveldb_iter_value(self.iterator, ctypes.byref(length))
        return as_python_string(pointer, size)
Beispiel #2
0
    def get_key(self):
        ''' Get the current key at the iterator

        :returns: The current key at the iterator
        '''
        size = new_native_size()
        pointer = LDB.leveldb_iter_key(self.iterator, get_reference_to(size))
        return as_python_string(pointer, size)
Beispiel #3
0
    def handle_error(self, error):
        ''' Given an underlying error, attempt to handle it.
        By default this will check if the supplied error is set and
        throw the message. It can be overridden to change this behaviour.

        :param error: The error to handle
        :throws DatabaseException: If an error has occurred
        '''
        message = as_python_string(error)
        if message:
            raise DatabaseException(message)
Beispiel #4
0
    def assert_no_error(self):
        ''' Check if there was an error after the last error.
        If there was, then throw an exception.

        :throws DatabaseException: If there was a problem with the iterator
        '''
        error = new_native_string()
        LDB.leveldb_iter_get_error(error, get_reference_to(error))
        message = as_python_string(error)
        if message:
            raise DatabaseException(message)
Beispiel #5
0
    def get_property(self, name):
        ''' Get an internal property value if it exists. Current
        properties that are supported are:

        * "leveldb.num-files-at-level<N>"
          return the number of files at level <N>, where <N> is an
          ASCII representation of a level number (e.g. "0").

        * "leveldb.stats"
          returns a multi-line string that describes statistics
          about the internal operation of the DB.

        :param name: The name of the property to retrieve
        :returns: The value of the property if it exists, or None
        '''
        result = None
        value  = LDB.leveldb_property_value(self.database, name)
        return as_python_string(value)
Beispiel #6
0
    def get(self, key, verify_checksum=False, fill_cache=True):
        ''' Delete the supplied value at the given key.

        :param key: The key to delete the value at
        :throws DatabaseException: If an error has occurred
        '''
        result  = None
        options = self.get_read_options(verify_checksum, fill_cache)

        try:
            error = new_native_string()
            size = new_native_size()
            value = LDB.leveldb_get(self.database, options, key, len(key),
                get_reference_to(size), get_reference_to(error))
            self.handle_error(error)
            return as_python_string(value, size)
        finally:
            if LDB and options:
                LDB.leveldb_readoptions_destroy(options)