def open(self): if not self.dbdir: url = ffi.NULL else: url = str(self.dbdir).encode() p_connection = ffi.new("monetdbe_database *") p_options = ffi.new("monetdbe_options *") p_options.memorylimit = self.memorylimit p_options.querytimeout = self.querytimeout p_options.sessiontimeout = self.sessiontimeout p_options.nr_threads = self.nr_threads result_code = lib.monetdbe_open(p_connection, url, p_options) connection = p_connection[0] errors = { 0: "OK", -1: "Allocation failed", -2: "Error in DB", } if result_code: if result_code == -2: error = ffi.string(lib.monetdbe_error(connection)).decode() lib.monetdbe_close(connection) else: error = errors.get(result_code, "unknown error") raise exceptions.OperationalError( f"Failed to open database: {error} (code {result_code})") return connection
def close(self) -> None: self._switch() if self._monetdbe_database: if lib.monetdbe_close(self._monetdbe_database): raise exceptions.OperationalError("Failed to close database") self.set_monetdbe_database(None) if self._active_context: self.set_active_context(None)
def close(self) -> None: if self._connection: if lib.monetdbe_close(self._connection): raise exceptions.OperationalError("Failed to close database") self.set_connection(None) if self._active_context: self.set_active_context(None) if not self.dbdir: self.set_in_memory_active(True)