public override int GetErrors(int pageIndex, int pageSize, ICollection<ErrorLogEntry> errorEntryList)
{
if (pageIndex < 0)
throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
if (pageSize < 0)
throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
const string sql = @"
SELECT
ErrorId,
Application,
Host,
Type,
Source,
Message,
User,
StatusCode,
TimeUtc
FROM
Error
ORDER BY
ErrorId DESC
LIMIT
@PageIndex * @PageSize,
@PageSize;
SELECT COUNT(*) FROM Error";
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
SQLiteParameterCollection parameters = command.Parameters;
parameters.Add("@PageIndex", DbType.Int16).Value = pageIndex;
parameters.Add("@PageSize", DbType.Int16).Value = pageSize;
connection.Open();
using (SQLiteDataReader reader = command.ExecuteReader())
{
if (errorEntryList != null)
{
while (reader.Read())
{
var id = Convert.ToString(reader["ErrorId"], CultureInfo.InvariantCulture);
var error = new Error
{
ApplicationName = reader["Application"].ToString(),
HostName = reader["Host"].ToString(),
Type = reader["Type"].ToString(),
Source = reader["Source"].ToString(),
Message = reader["Message"].ToString(),
User = reader["User"].ToString(),
StatusCode = Convert.ToInt32(reader["StatusCode"]),
Time = Convert.ToDateTime(reader["TimeUtc"]).ToLocalTime()
};
errorEntryList.Add(new ErrorLogEntry(this, id, error));
}
}
//
// Get the result of SELECT COUNT(*) FROM Page
//
reader.NextResult();
reader.Read();
return reader.GetInt32(0);
}
}
}