Ticket #2538: mythtv-recorded_tables_cleanup_mysql3_compat.patch

File mythtv-recorded_tables_cleanup_mysql3_compat.patch, 3.9 KB (added by sphery <mtdean@…>, 19 years ago)
  • programs/mythbackend/housekeeper.h

     
    3434    void runFillDatabase();
    3535    void CleanupMyOldRecordings(void);
    3636    void CleanupAllOldInUsePrograms(void);
     37    void CleanupRecordedTables(void);
    3738    bool threadrunning;
    3839    bool filldbRunning;
    3940    bool isMaster;
  • programs/mythbackend/housekeeper.cpp

     
    221221                }
    222222            }
    223223
    224             if (wantToRun("JobQueueCleanup", 1, 0, 24))
    225             {
     224            if (wantToRun("DailyCleanup", 1, 0, 24)) {
    226225                JobQueue::CleanupOldJobsInQueue();
    227                 updateLastrun("JobQueueCleanup");
    228             }
    229 
    230             if (wantToRun("InUseProgramsCleanup", 1, 0, 24))
    231             {
    232226                CleanupAllOldInUsePrograms();
    233                 updateLastrun("InUseProgramsCleanup");
     227                CleanupRecordedTables();
     228                updateLastrun("DailyCleanup");
    234229            }
    235230        }
    236231
     
    331326    query.exec();
    332327}
    333328
     329void HouseKeeper::CleanupRecordedTables(void)
     330{
     331    QString table[] = { "recordedprogram", "recordedrating",
     332                        "recordedcredits" };
     333    MSqlQuery query(MSqlQuery::InitCon());
     334    MSqlQuery deleteQuery(MSqlQuery::InitCon());
     335
     336    for (int tableIndex = 0; tableIndex < 3; tableIndex++)
     337    {
     338        query.prepare(QString("SELECT DISTINCT p.chanid, p.starttime "
     339                              "FROM %1 p LEFT JOIN recorded r "
     340                              "ON p.chanid = r.chanid "
     341                              "AND p.starttime = r.progstart "
     342                              "WHERE r.chanid IS NULL;")
     343                              .arg(table[tableIndex]));
     344        if (!query.exec() || !query.isActive())
     345        {
     346            MythContext::DBError("HouseKeeper Cleaning Recorded Tables", query);
     347            return;
     348        }
     349        deleteQuery.prepare(QString("DELETE FROM %1 "
     350                                    "WHERE chanid = :CHANID "
     351                                    "AND starttime = :STARTTIME;")
     352                                    .arg(table[tableIndex]));
     353        while (query.next())
     354        {
     355            deleteQuery.bindValue(":CHANID", query.value(0).toString());
     356            deleteQuery.bindValue(":STARTTIME", query.value(1).toString());
     357            deleteQuery.exec();
     358        }
     359    }
     360}
     361
    334362void *HouseKeeper::doHouseKeepingThread(void *param)
    335363{
    336364    HouseKeeper *hkeeper = (HouseKeeper*)param;
  • programs/mythfilldatabase/filldata.cpp

     
    27822782    query.bindValue(":OFFSET", offset);
    27832783    query.exec();
    27842784
    2785     query.prepare("DELETE p FROM recordedprogram p "
    2786                   "LEFT JOIN recorded r ON "
    2787                   "  p.chanid = r.chanid AND p.starttime = r.progstart "
    2788                   "WHERE r.chanid IS NULL;");
    2789     query.exec();
    2790 
    2791     query.prepare("DELETE p FROM recordedrating p "
    2792                   "LEFT JOIN recorded r ON "
    2793                   "  p.chanid = r.chanid AND p.starttime = r.progstart "
    2794                   "WHERE r.chanid IS NULL;");
    2795     query.exec();
    2796 
    2797     query.prepare("DELETE p FROM recordedcredits p "
    2798                   "LEFT JOIN recorded r ON "
    2799                   "  p.chanid = r.chanid AND p.starttime = r.progstart "
    2800                   "WHERE r.chanid IS NULL;");
    2801     query.exec();
    2802 
    28032785    query.prepare("DELETE FROM record WHERE (type = :SINGLE "
    28042786                  "OR type = :OVERRIDE OR type = :DONTRECORD) "
    28052787                  "AND enddate < NOW();");