예제 #1
0
 def close(self):
     if self._closed:
         return
     self._closed = True
     if self._db is not None:
         lib.sp_destroy(self._db)
     if self._env is not None:
         lib.sp_destroy(self._env)
예제 #2
0
 def close(self):
     if self._closed:
         return
     self._closed = True
     if self._db is not None:
         lib.sp_destroy(self._db)
     if self._env is not None:
         lib.sp_destroy(self._env)
예제 #3
0
 def __init__(self, path, flags):
     if self._env is not None or self._db is not None:
         raise RuntimeError('object was already initialized')
     # initialize environment
     env = lib.sp_env()
     if env == ffi.NULL:
         raise MemoryError('could not allocate environment')
     # set db directory and flags
     _flags = ffi.cast('int', flags)
     _path = ffi.new('char[]', path)
     r = lib.sp_ctl(env, lib.SPDIR, _flags, _path)
     if r != 0:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     # open db
     db = lib.sp_open(env)
     if db == ffi.NULL:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     self._env = env
     self._db = db
예제 #4
0
 def __init__(self, path, flags):
     if self._env is not None or self._db is not None:
         raise RuntimeError('object was already initialized')
     # initialize environment
     env = lib.sp_env()
     if env == ffi.NULL:
         raise MemoryError('could not allocate environment')
     # set db directory and flags
     _flags = ffi.cast('int', flags)
     _path = ffi.new('char[]', path)
     r = lib.sp_ctl(env, lib.SPDIR, _flags, _path)
     if r != 0:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     # open db
     db = lib.sp_open(env)
     if db == ffi.NULL:
         error = lib.sp_error(env)
         lib.sp_destroy(env)
         raise SophiaError(ffi.string(error))
     self._env = env
     self._db = db