Exemplo n.º 1
0
    protected static void ArchiveHistoryLogs()
    {
        DateTime date      = DateTime.Now.AddDays(-AppSettings.DBArchiver.HistoryLogsKeptForDays);
        string   wherePart = "WHERE Date < '" + date.ToDBString() + "'";

        //Archive to file
        string archiveQuery = "SELECT * FROM History " + wherePart;

        DBArchiverAPI.ExportToCSV(archiveQuery, date, HistoryFileName);

        //Delete from DB
        string deleteQuery = "DELETE FROM History " + wherePart;

        using (var bridge = ParserPool.Acquire(Database.Client))
        {
            bridge.Instance.ExecuteRawCommandNonQuery(deleteQuery);
        }
    }
Exemplo n.º 2
0
    protected static void ArchiveOfferwallsLogs()
    {
        DateTime date               = DateTime.Now.AddDays(-AppSettings.DBArchiver.OfferwallsLogsKeptForDays);
        string   wherePart          = "WHERE DateAdded < '" + date.ToDBString() + "'";
        int      recordsInEachBatch = 8000;
        int      batches            = (int)TableHelper.SelectScalar("SELECT COUNT(*) FROM OfferwallsLogs " + wherePart) / recordsInEachBatch;

        string archiveQuery = "SELECT TOP " + recordsInEachBatch + " * FROM OfferwallsLogs " + wherePart;

        string deleteQuery = string.Format(@"WITH CTE AS ({0}) DELETE FROM CTE", archiveQuery);

        for (int i = 0; i < batches; i++)
        {
            //Archive to file
            DBArchiverAPI.ExportToCSV(archiveQuery, date, OfferwallsLogsFileName, i);

            //Delete from DB
            using (var bridge = ParserPool.Acquire(Database.Client))
            {
                bridge.Instance.ExecuteRawCommandNonQuery(deleteQuery);
            }
        }
    }