Ticket #2342: programdata.cpp.diff

File programdata.cpp.diff, 1.5 KB (added by klaas.de.waal@…, 10 years ago)

Fix for "duplicate primary key" DB error with new EPG data

  • mythtv/libs/libmythtv/programdata.cpp

    diff --git a/mythtv/libs/libmythtv/programdata.cpp b/mythtv/libs/libmythtv/programdata.cpp
    index 4abbb6b..588389c 100644
    a b static bool delete_program(MSqlQuery &query, uint chanid, const QDateTime &st) 
    613613    return true;
    614614}
    615615
     616static bool program_exists(MSqlQuery &query, uint chanid, const QDateTime &st)
     617{
     618    query.prepare(
     619        "SELECT title FROM program "
     620        "WHERE chanid    = :CHANID AND "
     621        "      starttime = :OLDSTART");
     622    query.bindValue(":CHANID",   chanid);
     623    query.bindValue(":OLDSTART", st);
     624    if (!query.exec())
     625    {
     626        MythDB::DBError("program_exists", query);
     627    }
     628    if (query.next())
     629    {
     630        return true;
     631    }
     632    return false;
     633}
     634
    616635static bool change_program(MSqlQuery &query, uint chanid, const QDateTime &st,
    617636                           const QDateTime &new_st, const QDateTime &new_end)
    618637{
    bool DBEvent::MoveOutOfTheWayDB( 
    670689    else if (prog.starttime < endtime && prog.endtime > endtime)
    671690    {
    672691        // starts during, but ends after our program
     692        if (program_exists(query, chanid, endtime))
     693        {
     694            LOG(VB_EIT, LOG_DEBUG,
     695                QString("Deleting program '%1'").arg(prog.title));
     696            return delete_program(query, chanid, prog.starttime);
     697        }
    673698        return change_program(query, chanid, prog.starttime,
    674699                              endtime, prog.endtime);
    675700    }