Ticket #11541: 0001-simplify-handling-of-missing-endtime-at-end-of-file-.patch

File 0001-simplify-handling-of-missing-endtime-at-end-of-file-.patch, 4.4 KB (added by Karl Egly, 10 years ago)

tested patch

  • mythtv/libs/libmythtv/programdata.cpp

    From 8d64ee96ca411d6ded0cb0a22dd9bc32804e24ab Mon Sep 17 00:00:00 2001
    From: Karl Dietz <dekarl@mythtv.org>
    Date: Wed, 2 Apr 2014 20:00:53 +0200
    Subject: [PATCH] simplify handling of missing endtime at end of file in
     mythfilldatabase
    
    Instead of making up endtime of "next midnight" and "next 06:00 am" we
    just let the database fill in its default of 0000-00-00 00:00 and replace
    it later with whatever the next starttime is on that channel.
    
    Fixes #11541
    ---
     mythtv/libs/libmythtv/programdata.cpp |   41 +++++++++++----------------------
     1 file changed, 14 insertions(+), 27 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/programdata.cpp b/mythtv/libs/libmythtv/programdata.cpp
    index a626d82..34ad7e6 100644
    a b static QString denullify(const QString &str) 
    2828    return str.isNull() ? "" : str;
    2929}
    3030
     31static QVariant denullify(const QDateTime &dt)
     32{
     33    return dt.isNull() ? QVariant("0000-00-00 00:00:00") : QVariant(dt);
     34}
     35
    3136DBPerson::DBPerson(const DBPerson &other) :
    3237    role(other.role), name(other.name)
    3338{
    uint ProgInfo::InsertDB(MSqlQuery &query, uint chanid) const 
    10481053    query.bindValue(":CATEGORY",    denullify(category));
    10491054    query.bindValue(":CATTYPE",     cattype);
    10501055    query.bindValue(":STARTTIME",   starttime);
    1051     query.bindValue(":ENDTIME",     endtime);
     1056    query.bindValue(":ENDTIME",     denullify(endtime));
    10521057    query.bindValue(":CC",
    10531058                    subtitleType & SUB_HARDHEAR ? true : false);
    10541059    query.bindValue(":STEREO",
    void ProgramData::FixProgramList(QList<ProgInfo*> &fixlist) 
    11921197                (*cur)->endts   = (*it)->startts;
    11931198                (*cur)->endtime = (*it)->starttime;
    11941199            }
    1195             else
    1196             {
    1197                 (*cur)->endtime = (*cur)->starttime;
    1198                 if ((*cur)->endtime < QDateTime(
    1199                         (*cur)->endtime.date(), QTime(6, 0), Qt::UTC))
    1200                 {
    1201                     (*cur)->endtime = QDateTime(
    1202                         (*cur)->endtime.date(), QTime(6, 0), Qt::UTC);
    1203                 }
    1204                 else
    1205                 {
    1206                     (*cur)->endtime = QDateTime(
    1207                         (*cur)->endtime.date().addDays(1),
    1208                         QTime(0, 0), Qt::UTC);
    1209                 }
    1210 
    1211                 (*cur)->endts =
    1212                     MythDate::toString((*cur)->endtime, MythDate::kFilename);
    1213             }
     1200            /* if its the last programme in the file then leave its
     1201               endtime as 0000-00-00 00:00:00 so we can find it easily in
     1202               fix_end_times() */
    12141203        }
    12151204
    12161205        if (it == fixlist.end())
    int ProgramData::fix_end_times(void) 
    13471336    MSqlQuery query1(MSqlQuery::InitCon()), query2(MSqlQuery::InitCon());
    13481337
    13491338    querystr = "SELECT chanid, starttime, endtime FROM program "
    1350                "WHERE (DATE_FORMAT(endtime,'%H%i') = '0000') "
     1339               "WHERE endtime = '0000-00-00 00:00:00' "
    13511340               "ORDER BY chanid, starttime;";
    13521341
    13531342    if (!query1.exec(querystr))
    int ProgramData::fix_end_times(void) 
    13641353        endtime = query1.value(2).toString();
    13651354
    13661355        querystr = QString("SELECT chanid, starttime, endtime FROM program "
    1367                            "WHERE starttime BETWEEN '%1 00:00:00'"
    1368                            "AND '%2 23:59:59' AND chanid = '%3' "
     1356                           "WHERE starttime > '%1' "
     1357                           "AND chanid = '%2' "
    13691358                           "ORDER BY starttime LIMIT 1;")
    1370                            .arg(endtime.left(10))
    1371                            .arg(endtime.left(10))
     1359                           .arg(starttime)
    13721360                           .arg(chanid);
    13731361
    13741362        if (!query2.exec(querystr))
    int ProgramData::fix_end_times(void) 
    13821370        {
    13831371            count++;
    13841372            endtime = query2.value(1).toString();
    1385             querystr = QString("UPDATE program SET starttime = '%1', "
     1373            querystr = QString("UPDATE program SET "
    13861374                               "endtime = '%2' WHERE (chanid = '%3' AND "
    13871375                               "starttime = '%4');")
    1388                                .arg(starttime)
    13891376                               .arg(endtime)
    13901377                               .arg(chanid)
    13911378                               .arg(starttime);