Esempio n. 1
0
 def set(self, key, value):
     if self._closed:
         raise RuntimeError('db is closed')
     if not isinstance(key, bytes) or not isinstance(value, bytes):
         raise TypeError('byte string objects are supported')
     _key = ffi.new('char[]', key)
     _value = ffi.new('char[]', value)
     r = lib.sp_set(self._db, _key, ffi.sizeof(_key), _value, ffi.sizeof(_value))
     if r != 0:
         error = lib.sp_error(self._db)
         raise SophiaError(ffi.string(error))
Esempio n. 2
0
 def set(self, key, value):
     if self._closed:
         raise RuntimeError('db is closed')
     if not isinstance(key, bytes) or not isinstance(value, bytes):
         raise TypeError('byte string objects are supported')
     _key = ffi.new('char[]', key)
     _value = ffi.new('char[]', value)
     r = lib.sp_set(self._db, _key, ffi.sizeof(_key), _value,
                    ffi.sizeof(_value))
     if r != 0:
         error = lib.sp_error(self._db)
         raise SophiaError(ffi.string(error))
Esempio n. 3
0
 def delete(self, key):
     if self._closed:
         raise RuntimeError('db is closed')
     if not isinstance(key, bytes):
         raise TypeError('byte string objects are supported')
     _key = ffi.new('char[]', key)
     r = lib.sp_delete(self._db, _key, ffi.sizeof(_key))
     if r != 0:
         error = lib.sp_error(self._db)
         raise SophiaError(ffi.string(error))
Esempio n. 4
0
 def delete(self, key):
     if self._closed:
         raise RuntimeError('db is closed')
     if not isinstance(key, bytes):
         raise TypeError('byte string objects are supported')
     _key = ffi.new('char[]', key)
     r = lib.sp_delete(self._db, _key, ffi.sizeof(_key))
     if r != 0:
         error = lib.sp_error(self._db)
         raise SophiaError(ffi.string(error))
Esempio n. 5
0
 def get(self, key):
     if self._closed:
         raise RuntimeError('db is closed')
     if not isinstance(key, bytes):
         raise TypeError('byte string objects are supported')
     _key = ffi.new('char[]', key)
     _value = ffi.new('void**')
     _value_size = ffi.new('size_t*')
     r = lib.sp_get(self._db, _key, ffi.sizeof(_key), _value, _value_size)
     if r == -1:
         error = lib.sp_error(self._db)
         raise SophiaError(ffi.string(error))
     elif r == 0:
         raise KeyError('%s not found' % key)
     value = ffi.string(ffi.cast('char*', _value[0]), _value_size[0])
     libc.free(_value[0])
     return value
Esempio n. 6
0
 def get(self, key):
     if self._closed:
         raise RuntimeError('db is closed')
     if not isinstance(key, bytes):
         raise TypeError('byte string objects are supported')
     _key = ffi.new('char[]', key)
     _value = ffi.new('void**')
     _value_size = ffi.new('size_t*')
     r = lib.sp_get(self._db, _key, ffi.sizeof(_key), _value, _value_size)
     if r == -1:
         error = lib.sp_error(self._db)
         raise SophiaError(ffi.string(error))
     elif r == 0:
         raise KeyError('%s not found' % key)
     value = ffi.string(ffi.cast('char*', _value[0]), _value_size[0])
     libc.free(_value[0])
     return value