Ticket #3842: 3842-add-new-column-trunk-v1.patch

File 3842-add-new-column-trunk-v1.patch, 10.7 KB (added by danielk, 18 years ago)
  • libs/libmythtv/dbcheck.cpp

     
    1111#include "datadirect.h" // for DataDirectProcessor::FixProgramIDs
    1212
    1313/// This is the DB schema version expected by the running MythTV instance.
    14 const QString currentDatabaseVersion = "1199";
     14const QString currentDatabaseVersion = "1200";
    1515
    1616static bool UpdateDBVersionNumber(const QString &newnumber);
    1717static bool performActualUpdate(const QString updates[], QString version,
     
    294294airing. If this is "0" it usually means that this is a brand new show
    295295or a rebroadcast within the first two weeks.
    296296
     297'isnew' is a field that tells us if a listings source has marked this
     298program as a first showing of a program.
     299
    297300'programid' is the Tribune Media Service database record identifier
    298301for each program description. In general, these start with a two
    299302letter prefix, MV, EP, SP or SH that equate to the 'category_type'.
     
    32473250            return false;
    32483251    }
    32493252
     3253    if (dbver == "1199")
     3254    {
     3255        const QString updates[] = {
     3256"ALTER TABLE recorded        ADD COLUMN isnew TINYINT(1) DEFAULT 0;",
     3257"ALTER TABLE recordedprogram ADD COLUMN isnew TINYINT(1) DEFAULT 0;",
     3258"ALTER TABLE program         ADD COLUMN isnew TINYINT(1) DEFAULT 0;",
     3259"ALTER TABLE program         ADD INDEX (isnew);",
     3260""
     3261};
     3262        if (!performActualUpdate(updates, "1200", dbver))
     3263            return false;
     3264    }
     3265
    32503266//"ALTER TABLE cardinput DROP COLUMN preference;" in 0.22
    32513267//"ALTER TABLE channel DROP COLUMN atscsrcid;" in 0.22
    32523268//"ALTER TABLE recordedmarkup DROP COLUMN offset;" in 0.22
  • libs/libmythtv/datadirect.h

     
    9797    QString   stationid; // 12
    9898    QDateTime time;
    9999    QTime     duration;
    100     bool      repeat;
    101100    bool      isnew;
    102101    bool      stereo;
    103102    bool      subtitled;
     
    217216{
    218217  public:
    219218    DDStructureParser(DataDirectProcessor& _ddparent) :
    220         parent(_ddparent), saw_repeat(false), saw_new(false) {}
     219        parent(_ddparent) {}
    221220
    222221    bool startElement(const QString &pnamespaceuri, const QString &plocalname,
    223222                      const QString &pqname, const QXmlAttributes &pxmlatts);
     
    242241    DataDirectProductionCrew curr_productioncrew;
    243242    DataDirectGenre          curr_genre;
    244243    QString                  lastprogramid;
    245     bool                     saw_repeat;
    246     bool                     saw_new;
    247244};
    248245
    249246
  • libs/libmythtv/datadirect.cpp

     
    6868DataDirectSchedule::DataDirectSchedule() :
    6969    programid(""),              stationid(""),
    7070    time(QDateTime()),          duration(QTime()),
    71     repeat(false),              isnew(false),
     71    isnew(false),
    7272    stereo(false),              subtitled(false),
    7373    hdtv(false),                closecaptioned(false),
    7474    tvrating(""),
     
    168168        curr_schedule.duration = QTime(durstr.mid(2, 2).toInt(),
    169169                                       durstr.mid(5, 2).toInt(), 0, 0);
    170170
    171         QString isrepeat = pxmlatts.value("repeat");
    172         curr_schedule.repeat = (isrepeat == "true");
    173         saw_repeat |= !isrepeat.isEmpty();
    174 
    175         QString isnew = pxmlatts.value("new");
    176         curr_schedule.isnew = (isnew == "true");
    177         saw_new |= !isnew.isEmpty();
    178 
     171        curr_schedule.isnew = (pxmlatts.value("new") == "true");
    179172        curr_schedule.stereo = (pxmlatts.value("stereo") == "true");
    180173        curr_schedule.subtitled = (pxmlatts.value("subtitled") == "true");
    181174        curr_schedule.hdtv = (pxmlatts.value("hdtv") == "true");
     
    283276        query.prepare(
    284277            "INSERT INTO dd_schedule "
    285278            "     ( programid,  stationid,   scheduletime,   "
    286             "       duration,   isrepeat,    stereo,         "
     279            "       duration,   isnew,       stereo,         "
    287280            "       subtitled,  hdtv,        closecaptioned, "
    288281            "       tvrating,   partnumber,  parttotal,      "
    289             "       endtime,    isnew) "
     282            "       endtime ) "
    290283            "VALUES "
    291284            "     (:PROGRAMID, :STATIONID,  :TIME,           "
    292             "      :DURATION,  :ISREPEAT,   :STEREO,         "
     285            "      :DURATION,  :ISNEW,      :STEREO,         "
    293286            "      :SUBTITLED, :HDTV,       :CAPTIONED,      "
    294287            "      :TVRATING,  :PARTNUMBER, :PARTTOTAL,      "
    295             "      :ENDTIME,   :ISNEW)");
     288            "      :ENDTIME )");
    296289
    297290        query.bindValue(":PROGRAMID",   curr_schedule.programid);
    298291        query.bindValue(":STATIONID",   curr_schedule.stationid);
    299292        query.bindValue(":TIME",        curr_schedule.time);
    300293        query.bindValue(":DURATION",    curr_schedule.duration);
    301         query.bindValue(":ISREPEAT",    curr_schedule.repeat);
    302294        query.bindValue(":STEREO",      curr_schedule.stereo);
    303295        query.bindValue(":SUBTITLED",   curr_schedule.subtitled);
    304296        query.bindValue(":HDTV",        curr_schedule.hdtv);
     
    420412
    421413bool DDStructureParser::endDocument()
    422414{
    423     MSqlQuery query(MSqlQuery::DDCon());
    424     query.prepare(
    425         "INSERT INTO dd_state (sawrepeat, sawnew) "
    426         "VALUES (:SAWREPEAT, :SAWNEW)");
    427     query.bindValue(":SAWREPEAT", saw_repeat);
    428     query.bindValue(":SAWNEW",    saw_new);
    429 
    430     if (!query.exec())
    431         MythContext::DBError("Inserting into dd_state", query);
    432 
    433415    return true;
    434416}
    435417 
     
    616598void DataDirectProcessor::UpdateProgramViewTable(uint sourceid)
    617599{
    618600    MSqlQuery query(MSqlQuery::DDCon());
    619 
    620     query.prepare(
    621         "SELECT sawrepeat, sawnew "
    622         "FROM dd_state");
    623 
    624     if (!query.exec())
    625     {
    626         MythContext::DBError("Querying into dd_state", query);
    627         return;
    628     }
    629 
    630     if (!query.next())
    631     {
    632         VERBOSE(VB_IMPORTANT, LOC_ERR + "UpdateProgramViewTable no dd_state!");
    633         return;
    634     }
    635 
    636     bool saw_repeat = query.value(0).toUInt(); (void) saw_repeat;
    637     bool saw_new    = query.value(1).toUInt(); (void) saw_new;
    638 
    639 //    VERBOSE(VB_GENERAL, LOC + QString("Saw new: %1, saw repeat: %2")
    640 //            .arg(saw_new).arg(saw_repeat));
    641 
     601   
    642602    if (!query.exec("TRUNCATE TABLE dd_v_program;"))
    643603        MythContext::DBError("Truncating temporary table dd_v_program", query);
    644604
     
    646606        "INSERT INTO dd_v_program "
    647607        "     ( chanid,         starttime,       endtime,         "
    648608        "       title,          subtitle,        description,     "
    649         "       airdate,        stars,           previouslyshown, "
     609        "       airdate,        stars,           isnew, "
    650610        "       stereo,         subtitled,       hdtv,            "
    651611        "       closecaptioned, partnumber,      parttotal,       "
    652612        "       seriesid,       originalairdate, showtype,        "
     
    654614        "       tvrating,       mpaarating,      programid )      "
    655615        "SELECT chanid,         scheduletime,    endtime,         "
    656616        "       title,          subtitle,        description,     "
    657         "       year,           stars,           %1,              "
     617        "       year,           stars,           isnew,           "
    658618        "       stereo,         subtitled,       hdtv,            "
    659619        "       closecaptioned, partnumber,      parttotal,       "
    660620        "       seriesid,       originalairdate, showtype,        "
     
    665625        "       (channel.xmltvid       = dd_schedule.stationid) AND "
    666626        "       (channel.sourceid      = :SOURCEID))";
    667627
    668     QString repeat = (saw_new) ?
    669         "(not isnew) AND "
    670         "(SUBSTRING(dd_program.programid,1,2) IN ('EP', 'SH'))" :
    671         "isrepeat";
     628    query.prepare(qstr);
    672629
    673     query.prepare(qstr.arg(repeat));
    674 
    675630    query.bindValue(":SOURCEID", sourceid);
    676631
    677632    if (!query.exec())
     
    847802    if (!query.exec("INSERT IGNORE INTO program (chanid, starttime, endtime, "
    848803                    "title, subtitle, description, "
    849804                    "showtype, category, category_type, "
    850                     "airdate, stars, previouslyshown, stereo, subtitled, "
     805                    "airdate, stars, isnew, stereo, subtitled, "
    851806                    "hdtv, closecaptioned, partnumber, parttotal, seriesid, "
    852807                    "originalairdate, colorcode, syndicatedepisodenumber, "
    853808                    "programid) "
     
    856811                    "DATE_ADD(endtime, INTERVAL channel.tmoffset MINUTE), "
    857812                    "title, subtitle, description, "
    858813                    "showtype, dd_genre.class, category_type, "
    859                     "airdate, stars, previouslyshown, stereo, subtitled, "
     814                    "airdate, stars, isnew, stereo, subtitled, "
    860815                    "hdtv, closecaptioned, partnumber, parttotal, seriesid, "
    861816                    "originalairdate, colorcode, syndicatedepisodenumber, "
    862817                    "dd_v_program.programid FROM (dd_v_program, channel) "
     
    13161271{
    13171272    QMap<QString,QString> dd_tables;
    13181273
    1319     dd_tables["dd_state"] =
    1320         "( sawrepeat bool,               sawnew bool )";
    1321 
    13221274    dd_tables["dd_station"] =
    13231275        "( stationid char(12),           callsign char(10),     "
    13241276        "  stationname varchar(40),      affiliate varchar(25), "
     
    13431295    dd_tables["dd_schedule"] =
    13441296        "( programid char(40),           stationid char(12), "
    13451297        "  scheduletime datetime,        duration time,      "
    1346         "  isrepeat bool,                stereo bool,        "
     1298        "  isnew tinyint,                stereo bool,        "
    13471299        "  subtitled bool,               hdtv bool,          "
    13481300        "  closecaptioned bool,          tvrating char(5),   "
    13491301        "  partnumber int,               parttotal int,      "
    1350         "  endtime datetime,             isnew bool,         "
     1302        "  endtime datetime, "
    13511303        "INDEX progidx (programid) )";
    13521304
    13531305    dd_tables["dd_program"] =
     
    13671319        "  subtitle varchar(128),        description text,            "
    13681320        "  category varchar(64),         category_type varchar(64),   "
    13691321        "  airdate year,                 stars float unsigned,        "
    1370         "  previouslyshown tinyint,      isrepeat bool,               "
     1322        "  isnew tinyint,                                             "
    13711323        "  stereo bool,                  subtitled bool,              "
    13721324        "  hdtv bool,                    closecaptioned bool,         "
    13731325        "  partnumber int,               parttotal int,               "