/// <summary> A SqliteResultCode extension method that throw on error. </summary> /// <exception cref="SqliteException"> Thrown when a Sqlite error condition occurs. </exception> /// <param name="resultCode"> The resultCode to act on. </param> public static void ThrowOnError(this SqliteResultCode resultCode) { if (!resultCode.IsSuccessCode()) { throw new SqliteException(resultCode); } }
/// <summary> Gets error string. </summary> /// <param name="errorCode"> The error code. </param> /// <param name="database"> The database. </param> /// <returns> The error string. </returns> private static string GetErrorString(SqliteResultCode errorCode, SqliteDatabaseHandle database) { string errorString = errorCode.ToString(); return(database != null ? "{0}: {1}".FormatInvariant(errorString, database.Context.sqlite3_errmsg(database, database.IsDatabaseInMaintenanceMode)) : errorString); }
/// <summary> /// A SqliteResultCode extension method that query if 'resultCode' is success code. /// </summary> /// <param name="resultCode"> The resultCode to act on. </param> /// <returns> True if success code, false if not. </returns> public static bool IsSuccessCode(this SqliteResultCode resultCode) { return(successCodes.Contains(resultCode)); }
/// <summary> Constructor. </summary> /// <param name="message"> The message. </param> /// <param name="errorCode"> The error code. </param> public SqliteException(string message, SqliteResultCode errorCode) : base(message, (int)errorCode) { }
/// <summary> Constructor. </summary> /// <param name="errorCode"> The error code. </param> public SqliteException(SqliteResultCode errorCode) : base("An SQLite database error occured.", (int)errorCode) { }
/// <summary> Constructs the object. </summary> /// <param name="pUserData"> Should be null. </param> /// <param name="errorCode"> The error code. The type of this object value should be /// <see cref="Int32" /> or <see cref="SqliteResultCode" />. </param> /// <param name="message"> The error message, if any. </param> /// <param name="data"> The extra data, if any. </param> internal LogEventArgs(object pUserData, SqliteResultCode errorCode, string message, object data) { ErrorCode = errorCode; Message = message; Data = data; }
/// <summary> Constructor. </summary> /// <param name="errorCode"> The error code. </param> /// <param name="database"> The database. </param> internal SqliteException(SqliteResultCode errorCode, SqliteDatabaseHandle database) : base(GetErrorString(errorCode, database), (int)errorCode) { }
/// <summary> Constructor. </summary> /// <param name="errorCode"> The error code. </param> public SqliteException(SqliteResultCode errorCode) : this(errorCode, null) { }
/// <summary> Sqlite 3 step return rowid. </summary> /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception> /// <param name="db"> The database. </param> /// <param name="stmt"> The statement. </param> /// <param name="code"> [out] The code. </param> /// <returns> A long. </returns> internal long sqlite3_step_return_rowid(SqliteDatabaseHandle db, SqliteStatementHandle stmt, out SqliteResultCode code) { if (db == null) { throw new ArgumentNullException(nameof(db)); } if (stmt == null) { throw new ArgumentNullException(nameof(stmt)); } lock (_stepLocker) { stmt.CheckMaintenanceMode(); code = (SqliteResultCode)DbProviderOperations.sqlite3_step(stmt.Statement); return(code.IsSuccessCode() ? DbProviderOperations.sqlite3_last_insert_rowid(stmt.ForMaintenance ? db.MaintenanceDb : db.Db) : -1); } }
/// <summary> Sqlite 3 errstr. </summary> /// <param name="rc"> The rectangle. </param> /// <returns> A string. </returns> internal string sqlite3_errstr(SqliteResultCode rc) { return(DbProviderOperations.sqlite3_errstr((int)rc)); }