#pragma warning restore CA1825 // Avoid zero-length array allocations. public static string DotNetStr(DbRetCode ret) { if (ret > DotNetLowError && ret <= (DotNetLowError + dotNetStr.Length)) { return(dotNetStr[(int)ret - (int)DotNetLowError - 1]); } else { return(UnknownStr(ret)); } }
public static void CheckRetCode(DbRetCode ret) { if (ret != DbRetCode.SUCCESS) { string errStr; if (ret > MdbLowError && ret <= DbRetCode.LAST_ERRCODE) { errStr = DbLib.mdb_strerror(ret); } else { errStr = DotNetStr(ret); } throw new LmdbException(ret, errStr); } }
/// <summary>Constructor.</summary> /// <param name="config">Configuration to use.</param> public LmdbEnvironment(LmdbEnvironmentConfiguration config = null) { // so that we can refer back to the Environment instance instanceHandle = GCHandle.Alloc(this, GCHandleType.WeakTrackResurrection); DbRetCode ret = DbLib.mdb_env_create(out IntPtr envHandle); if (ret == DbRetCode.SUCCESS) { var ret2 = DbLib.mdb_env_set_userctx(envHandle, (IntPtr)instanceHandle); if (ret2 == DbRetCode.SUCCESS) { this.env = envHandle; } else { ret = ret2; DbLib.mdb_env_close(envHandle); } } ErrorUtil.CheckRetCode(ret); if (config != null) { this.autoReduceMapSizeIn32BitProcess = config.AutoReduceMapSizeIn32BitProcess; if (config.MapSize.HasValue) { this.SetMapSize(config.MapSize.Value); } if (config.MaxDatabases.HasValue) { this.MaxDatabases = config.MaxDatabases.Value; } if (config.MaxReaders.HasValue) { this.MaxReaders = config.MaxReaders.Value; } } }
public static string UnknownStr(DbRetCode ret) { return($"Unknown LMDB error code: {ret}."); }
public static string mdb_strerror(DbRetCode error) { IntPtr errStr = _mdb_strerror((int)error); return(Marshal.PtrToStringAnsi(errStr)); }
/// <summary>Constructor.</summary> /// <param name="errorCode">Native error code.</param> public LmdbException(DbRetCode errorCode, string message) : base(message) { this.errorCode = errorCode; }
/// <summary>Constructor.</summary> /// <param name="errorCode">Native error code.</param> public LmdbException(DbRetCode errorCode) { this.errorCode = errorCode; }