Index: programs/mythfilldatabase/filldata.cpp =================================================================== --- programs/mythfilldatabase/filldata.cpp (revision 9370) +++ programs/mythfilldatabase/filldata.cpp (working copy) @@ -60,6 +60,7 @@ bool dddataretrieved = false; bool mark_repeats = true; bool channel_updates = false; +bool insert_new_channels = true; int maxDays = 0; int listing_wrap_offset = 0; @@ -791,128 +792,152 @@ MSqlQuery no_xmltvid_q(MSqlQuery::DDCon()); MSqlQuery query(MSqlQuery::DDCon()); MSqlQuery chan_update_q(MSqlQuery::DDCon()); + MSqlQuery purge_new_chans(MSqlQuery::DDCon()); QString querystr; ddprocessor.updateStationViewTable(); - // Find all the channels in the dd_v_station temp table - // where there is no channel with the same xmltvid in the - // DB using the same source. - no_xmltvid_q.prepare( - "SELECT dd_v_station.stationid, dd_v_station.callsign," - " dd_v_station.stationname, dd_v_station.channel," - " dd_v_station.fccchannelnumber, dd_v_station.channelMinor " - "FROM dd_v_station LEFT JOIN channel ON " - " dd_v_station.stationid = channel.xmltvid AND " - " channel.sourceid = :SOURCEID " - "WHERE channel.chanid IS NULL;"); - no_xmltvid_q.bindValue(":SOURCEID", source.id); + if (insert_new_channels) + { + // Find all the channels in the dd_v_station temp table + // where there is no channel with the same xmltvid in the + // DB using the same source. + no_xmltvid_q.prepare( + "SELECT dd_v_station.stationid, dd_v_station.callsign," + " dd_v_station.stationname, dd_v_station.channel," + " dd_v_station.fccchannelnumber, dd_v_station.channelMinor " + "FROM dd_v_station LEFT JOIN channel ON " + " dd_v_station.stationid = channel.xmltvid AND " + " channel.sourceid = :SOURCEID " + "WHERE channel.chanid IS NULL;"); + no_xmltvid_q.bindValue(":SOURCEID", source.id); - if (!no_xmltvid_q.exec()) - MythContext::DBError("Selecting new channels", no_xmltvid_q); + if (!no_xmltvid_q.exec()) + MythContext::DBError("Selecting new channels", no_xmltvid_q); - if (no_xmltvid_q.isActive() && no_xmltvid_q.size() > 0) - { - while (no_xmltvid_q.next()) + if (no_xmltvid_q.isActive() && no_xmltvid_q.size() > 0) { - // Get the important info from our first query - QString xmltvid = no_xmltvid_q.value(0).toString(); - QString callsign = no_xmltvid_q.value(1).toString(); - QString name = no_xmltvid_q.value(2).toString(); - QString channum = no_xmltvid_q.value(3).toString(); - int freqid = no_xmltvid_q.value(4).toInt(); - QString minor = no_xmltvid_q.value(5).toString(); - QString tvformat = "Default"; - callsign = (callsign == "") ? name : callsign; - - int major = 0, atscsrcid = -9999; - if (minor != "") + while (no_xmltvid_q.next()) { - major = channum.toInt(); - atscsrcid = (major << 8) | minor.toInt(); - tvformat = "atsc"; - // default channum number - channum += SourceUtil::GetChannelSeparator(source.id) + minor; - } - else - { - freqid = channum.toInt(); - } + // Get the important info from our first query + QString xmltvid = no_xmltvid_q.value(0).toString(); + QString callsign = no_xmltvid_q.value(1).toString(); + QString name = no_xmltvid_q.value(2).toString(); + QString channum = no_xmltvid_q.value(3).toString(); + int freqid = no_xmltvid_q.value(4).toInt(); + QString minor = no_xmltvid_q.value(5).toString(); + QString tvformat = "Default"; + callsign = (callsign == "") ? name : callsign; - // First check if channel already in DB, but without xmltvid - query.prepare("SELECT chanid FROM channel " - "WHERE sourceid = :SOURCEID AND " - " (channum=:CHANNUM OR atscsrcid=:ATSCSRCID)"); - query.bindValue(":SOURCEID", source.id); - query.bindValue(":CHANNUM", channum); - query.bindValue(":ATSCSRCID", atscsrcid); + int major = 0, atscsrcid = -9999; + if (minor != "") + { + major = channum.toInt(); + atscsrcid = (major << 8) | minor.toInt(); + tvformat = "atsc"; + // default channum number + channum += SourceUtil::GetChannelSeparator(source.id) + minor; + } + else + { + freqid = channum.toInt(); + } - if (!query.exec() || !query.isActive()) - { - MythContext::DBError( - "Getting chanid of existing channel", query); - continue; // go on to next channel without xmltv - } + // First check if channel already in DB, but without xmltvid + query.prepare("SELECT chanid FROM channel " + "WHERE sourceid = :SOURCEID AND " + " (channum=:CHANNUM OR atscsrcid=:ATSCSRCID)"); + query.bindValue(":SOURCEID", source.id); + query.bindValue(":CHANNUM", channum); + query.bindValue(":ATSCSRCID", atscsrcid); - if (query.size() > 0) - { - // The channel already exists in DB, at least once, - // so set the xmltvid.. - chan_update_q.prepare( - "UPDATE channel " - "SET xmltvid = :XMLTVID " - "WHERE chanid = :CHANID AND sourceid = :SOURCEID"); + if (!query.exec() || !query.isActive()) + { + MythContext::DBError( + "Getting chanid of existing channel", query); + continue; // go on to next channel without xmltv + } - while (query.next()) + if (query.size() > 0) { - uint chanid = query.value(0).toInt(); - chan_update_q.bindValue(":CHANID", chanid); - chan_update_q.bindValue(":XMLTVID", xmltvid); - chan_update_q.bindValue(":SOURCEID", source.id); - if (!chan_update_q.exec() || !chan_update_q.isActive()) + // The channel already exists in DB, at least once, + // so set the xmltvid.. + chan_update_q.prepare( + "UPDATE channel " + "SET xmltvid = :XMLTVID " + "WHERE chanid = :CHANID AND sourceid = :SOURCEID"); + + while (query.next()) { - MythContext::DBError( - "Updating XMLTVID of existing channel", chan_update_q); - continue; // go on to next instance of this channel + uint chanid = query.value(0).toInt(); + chan_update_q.bindValue(":CHANID", chanid); + chan_update_q.bindValue(":XMLTVID", xmltvid); + chan_update_q.bindValue(":SOURCEID", source.id); + if (!chan_update_q.exec() || !chan_update_q.isActive()) + { + MythContext::DBError( + "Updating XMLTVID of existing channel", chan_update_q); + continue; // go on to next instance of this channel + } } + continue; // go on to next channel without xmltv } - continue; // go on to next channel without xmltv - } - // The channel doesn't exist in the DB, insert it... - int mplexid = -1, majorC, minorC, chanid = 0; - long long freq; - get_atsc_stuff(channum, source.id, freqid, - majorC, minorC, freq); + // The channel doesn't exist in the DB, insert it... + int mplexid = -1, majorC, minorC, chanid = 0; + long long freq; + get_atsc_stuff(channum, source.id, freqid, + majorC, minorC, freq); - if (minorC > 0 && freq >= 0) - { - mplexid = ChannelUtil::CreateMultiplex( - source.id, "atsc", freq, "8vsb"); - } + if (minorC > 0 && freq >= 0) + { + mplexid = ChannelUtil::CreateMultiplex( + source.id, "atsc", freq, "8vsb"); + } - if ((mplexid > 0) || (minorC == 0)) - chanid = ChannelUtil::CreateChanID(source.id, channum); + if ((mplexid > 0) || (minorC == 0)) + chanid = ChannelUtil::CreateChanID(source.id, channum); - if (chanid > 0) - { - QString icon = ""; - int serviceid = 0; - bool oag = false; // use on air guide - bool hidden = false; - bool hidden_in_guide = false; + if (chanid > 0) + { + QString icon = ""; + int serviceid = 0; + bool oag = false; // use on air guide + bool hidden = false; + bool hidden_in_guide = false; - ChannelUtil::CreateChannel( - mplexid, source.id, chanid, - callsign, name, channum, - serviceid, majorC, minorC, - oag, hidden, hidden_in_guide, - freqid, icon, tvformat, - xmltvid); + ChannelUtil::CreateChannel( + mplexid, source.id, chanid, + callsign, name, channum, + serviceid, majorC, minorC, + oag, hidden, hidden_in_guide, + freqid, icon, tvformat, + xmltvid); + } } } } + else // !insert_new_channels ("--no-new-channels" option) + { + // Delete all channels from the temp DB that are not already in + // the main channel DB + VERBOSE(VB_GENERAL, QString("Purging unused channels")); + purge_new_chans.prepare( + "DELETE dd_v_station " + "FROM dd_v_station " + "LEFT JOIN channel ON " + " dd_v_station.stationid = channel.xmltvid AND " + " channel.sourceid = :SOURCEID " + "WHERE channel.chanid IS NULL;"); + purge_new_chans.bindValue(":SOURCEID", source.id); + if (!purge_new_chans.exec()) + MythContext::DBError("Purging new channels", purge_new_chans); + else + VERBOSE(VB_GENERAL, + QString(" Purged %1 rows").arg(purge_new_chans.numRowsAffected())); + } + if (channel_updates) { // @@ -3447,6 +3472,10 @@ { channel_updates = true; } + else if (!strcmp(a.argv()[argpos], "--no-new-channels")) + { + insert_new_channels = false; + } else if (!strcmp(a.argv()[argpos], "--graboptions")) { if (((argpos + 1) >= a.argc())) @@ -3652,6 +3681,15 @@ cout << " override custom channel names, which is why it is\n"; cout << " off by default.\n"; cout << "\n"; + cout << "--no-new-channels\n"; + cout << " When using DataDirect, don't add data for new\n"; + cout << " channels added (usually without your knowledge) to your\n"; + cout << " DD lineup. This prevents your listings from being\n"; + cout << " flooded with channels you don't get, but also means\n"; + cout << " you have to run mythfilldatabase without this option\n"; + cout << " whenever you really want to add new channels to your\n"; + cout << " listings in Myth.\n"; + cout << "\n"; cout << "--graboptions <\"options\">\n"; cout << " Pass options to grabber\n"; cout << "\n";