public Exception ProcessException(Exception innerException, DbConnection connection, string commandText, DbTransaction transaction) { Logger.LogException(innerException); if (innerException is SqliteException ex) { SQLException sqlEx; #if MICROSOFT_DATA_SQLITE var errorCode = (SqliteResultCode)ex.SqliteErrorCode; #elif SYSTEM_DATA_SQLITE var errorCode = (SqliteResultCode)ex.ErrorCode; #endif switch (errorCode) { case SqliteResultCode.Corrupt: case SqliteResultCode.NotADb: case SqliteResultCode.Perm: case SqliteResultCode.IoErr: case SqliteResultCode.CantOpen: case SqliteResultCode.Full: case SqliteResultCode.Auth: { return(new FileAccessException(errorCode.ToString(), innerException)); } case SqliteResultCode.ReadOnly: { sqlEx = new ReadOnlyException(null, innerException); break; } case SqliteResultCode.Locked: { sqlEx = new ConnectionException("file is locked", ex); break; } case SqliteResultCode.Constraint: { if (innerException.Message.IndexOf("UNIQUE constraint failed", StringComparison.OrdinalIgnoreCase) >= 0) { sqlEx = new UniqueConstraintException(null, innerException); } else { sqlEx = new ConstraintException(null, innerException); } break; } default: { sqlEx = new SQLException(null, innerException); break; } } if (connection != null) { try { sqlEx.ConnectionString = connection.ConnectionString; sqlEx.ConnectionState = connection.State.ToString(); } catch (ObjectDisposedException) { sqlEx.ConnectionState = "Disposed"; } } if (connection != null) { sqlEx.CommandText = commandText; //newEx.Data.Add("CommandText", comm.CommandText); } return(sqlEx); } #if MICROSOFT_DATA_SQLITE else if ((innerException is InvalidOperationException ioex) && ioex.Source == "Microsoft.Data.Sqlite") { return(new SQLException(null, innerException) { CommandText = commandText }); }
protected override Exception ThrowExceptionHelper(DbConnection conn, DbCommand comm, Exception innerException) { if (innerException is SQLiteException) { SQLException sqlEx; var ex = innerException as SQLiteException; #if Mono var errorCode = ex.ErrorCode; #else var errorCode = ex.ResultCode; #endif switch (errorCode) { case SQLiteErrorCode.Corrupt: #if Mono case SQLiteErrorCode.NotADatabase: #else case SQLiteErrorCode.NotADb: #endif case SQLiteErrorCode.Perm: #if Mono case SQLiteErrorCode.IOErr: #else case SQLiteErrorCode.IoErr: #endif case SQLiteErrorCode.CantOpen: case SQLiteErrorCode.Full: case SQLiteErrorCode.Auth: { return new FileAccessException(errorCode.ToString(), innerException); } case SQLiteErrorCode.ReadOnly: { sqlEx = new ReadOnlyException(null, innerException); break; } case SQLiteErrorCode.Locked: { sqlEx = new ConnectionException("file is locked", ex); break; } case SQLiteErrorCode.Constraint: { if (innerException.Message.IndexOf("UNIQUE constraint failed", StringComparison.OrdinalIgnoreCase) >= 0) { sqlEx = new UniqueConstraintException(null, innerException); } else { sqlEx = new ConstraintException(null, innerException); } break; } default: { sqlEx = new SQLException(null, innerException); break; } } if (conn != null) { try { sqlEx.ConnectionString = conn.ConnectionString; sqlEx.ConnectionState = conn.State.ToString(); } catch (ObjectDisposedException) { sqlEx.ConnectionState = "Disposed"; } } if (comm != null) { sqlEx.CommandText = comm.CommandText; //newEx.Data.Add("CommandText", comm.CommandText); } return sqlEx; } else { return new ORMException(null, innerException); } }