Index: mythtv/libs/libmythtv/channelutil.cpp
===================================================================
--- mythtv.orig/libs/libmythtv/channelutil.cpp	2006-04-24 09:59:18.000000000 +0100
+++ mythtv/libs/libmythtv/channelutil.cpp	2006-04-26 18:47:34.000000000 +0100
@@ -8,44 +8,29 @@
 
 static uint get_dtv_multiplex(
     int         db_source_id,  QString     sistandard,
-    uint        frequency,     QString     modulation,
+    uint        frequency,     QString     /*modulation*/,
     // DVB specific
     int         transport_id,  int         network_id,
-    int         symbol_rate,   signed char bandwidth,
-    signed char polarity,      signed char inversion,
-    signed char trans_mode,
-    QString     inner_FEC,     QString      constellation,
-    signed char hierarchy,     QString      hp_code_rate,
-    QString     lp_code_rate,  QString      guard_interval)
+    int         /*symbol_rate*/,   signed char /*bandwidth*/,
+    signed char /*polarity*/,      signed char /*inversion*/,
+    signed char /*trans_mode*/,
+    QString     /*inner_FEC*/,     QString      /*constellation*/,
+    signed char /*hierarchy*/,     QString      /*hp_code_rate*/,
+    QString     /*lp_code_rate*/,  QString      /*guard_interval*/)
 {
-    bool modnl = !modulation.isNull();
-    bool ifecn = !inner_FEC.isNull();
-    bool consn = !constellation.isNull();
-    bool hpcrn = !hp_code_rate.isNull();
-    bool lpcrn = !lp_code_rate.isNull();
-    bool ginul = !guard_interval.isNull();
-
     QString qstr = 
         QString("SELECT mplexid "
                 "FROM dtv_multiplex "
                 "WHERE sourceid     = :SOURCEID   "
-                "  AND sistandard   = :SISTANDARD "
-                "  AND frequency    = :FREQUENCY  ") +
-        QString((modnl)            ? "AND modulation   = :MODULATION  " : "") +
-        QString((transport_id > 0) ? "AND transportid  = :TRANSPORTID " : "") +
-        QString((network_id   > 0) ? "AND networkid    = :NETWORKID   " : "") +
-        QString((symbol_rate >= 0) ? "AND symbolrate   = :SYMBOLRATE  " : "") +
-        QString((bandwidth   >= 0) ? "AND bandwidth    = :BANDWIDTH   " : "") +
-        QString((polarity    >= 0) ? "AND polarity     = :POLARITY    " : "") +
-        QString((inversion   >= 0) ? "AND inversion    = :INVERSION   " : "") +
-        QString((trans_mode  >= 0) ? "AND transmission_mode=:TRANS_MODE ":"") +
-        QString((ifecn)            ? "AND fec          = :INNER_FEC   " : "") +
-        QString((consn)            ? "AND constellation= :CONSTELLATION ":"") +
-        QString((hierarchy   >= 0) ? "AND hierarchy    = :HIERARCHY   " : "") +
-        QString((hpcrn)            ? "AND hp_code_rate = :HP_CODE_RATE ": "") +
-        QString((lpcrn)            ? "AND lp_code_rate = :LP_CODE_RATE ": "") +
-        QString((ginul)            ? "AND guard_interval=:GUARD_INTERVAL ":"");
+                "  AND sistandard   = :SISTANDARD ");
+
+    if (QString::compare(sistandard,"atsc") == 0)
+    {
+                qstr.append("  AND frequency    = :FREQUENCY  ");
+    }
 
+    qstr.append(QString((transport_id > 0) ? "AND transportid  = :TRANSPORTID " : ""));
+    qstr.append(QString((network_id   > 0) ? "AND networkid    = :NETWORKID   " : ""));
 
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare(qstr);
@@ -54,37 +39,11 @@
     query.bindValue(":FREQUENCY",         frequency);
     query.bindValue(":SISTANDARD",        sistandard);
 
-    if (modnl)
-        query.bindValue(":MODULATION",    modulation);
     if (transport_id > 0)
         query.bindValue(":TRANSPORTID",   transport_id);
     if (network_id > 0)
         query.bindValue(":NETWORKID",     network_id);
 
-    if (symbol_rate >= 0)
-        query.bindValue(":SYMBOLRATE",    symbol_rate);
-    if (bandwidth >= 0)
-        query.bindValue(":BANDWIDTH",     QString("%1").arg((char)bandwidth));
-    if (polarity >= 0)
-        query.bindValue(":POLARITY",      QString("%1").arg((char)polarity));
-    if (inversion >= 0)
-        query.bindValue(":INVERSION",     QString("%1").arg((char)inversion));
-    if (trans_mode >= 0)
-        query.bindValue(":TRANS_MODE",    QString("%1").arg((char)trans_mode));
-
-    if (ifecn)
-        query.bindValue(":INNER_FEC",     inner_FEC);
-    if (consn)
-        query.bindValue(":CONSTELLATION", constellation);
-    if (hierarchy >= 0)
-        query.bindValue(":HIERARCHY",     QString("%1").arg((char)hierarchy));
-    if (hpcrn)
-        query.bindValue(":HP_CODE_RATE",  hp_code_rate);
-    if (lpcrn)
-        query.bindValue(":LP_CODE_RATE",  lp_code_rate);
-    if (ginul)
-        query.bindValue(":GUARD_INTERVAL",guard_interval);
-
     if (!query.exec() || !query.isActive())
     {
         MythContext::DBError("check_for_matching_dtv_multiplex 2", query);
@@ -128,25 +87,45 @@
     if (mplex)
     {
         VERBOSE(VB_SIPARSER, QString("insert_dtv_multiplex -- ") +
-                QString("already exists %1").arg(mplex));
-        return mplex;
+                QString("updating %1").arg(mplex));
+        QString qstr = QString(
+            "UPDATE dtv_multiplex SET "
+            "  sourceid=:SOURCEID, sistandard=:SISTANDARD, "
+            "  frequency=:FREQUENCY, modulation=:MODULATION, "
+            "  transportid=:TRANSPORTID, networkid=:NETWORKID, "
+            "  symbolrate=:SYMBOLRATE, bandwidth=:BANDWIDTH, "
+            "  polarity=:POLARITY, inversion=:INVERSION, "
+            "  transmission_mode=:TRANS_MODE, fec=:INNER_FEC, "
+            "  constellation=:CONSTELLATION, hierarchy=:HIERARCHY, "
+            "  hp_code_rate=:HP_CODE_RATE, lp_code_rate=:LP_CODE_RATE, "
+            "  guard_interval=:GUARD_INTERVAL "
+            "WHERE "
+            "  sourceid=:SOURCEID AND sistandard=:SISTANDARD "
+            "  AND transportid=:TRANSPORTID AND networkid=:NETWORKID ");
+        if (QString::compare(sistandard,"atsc") == 0)
+        {
+            qstr.append("  AND frequency    = :FREQUENCY  ");
+        }
+        query.prepare(qstr);
+    }
+    else
+    {
+        query.prepare(
+            "INSERT into dtv_multiplex "
+            "  (sourceid,        sistandard,        frequency,  "
+            "   modulation,      transportid,       networkid,  "
+            "   symbolrate,      bandwidth,         polarity,   "
+            "   inversion,       transmission_mode,             "
+            "   fec,             constellation,     hierarchy,  "
+            "   hp_code_rate,    lp_code_rate,      guard_interval) "
+            "VALUES "
+            "  (:SOURCEID,       :SISTANDARD,       :FREQUENCY, "
+            "   :MODULATION,     :TRANSPORTID,      :NETWORKID, "
+            "   :SYMBOLRATE,     :BANDWIDTH,        :POLARITY,  "
+            "   :INVERSION,      :TRANS_MODE,                   "
+            "   :INNER_FEC,      :CONSTELLATION,    :HIERARCHY, "
+            "   :HP_CODE_RATE,   :LP_CODE_RATE,     :GUARD_INTERVAL);");
     }
-
-    query.prepare(
-        "INSERT INTO dtv_multiplex "
-        "  (sourceid,        sistandard,        frequency,  "
-        "   modulation,      transportid,       networkid,  "
-        "   symbolrate,      bandwidth,         polarity,   "
-        "   inversion,       transmission_mode,             "
-        "   fec,             constellation,     hierarchy,  "
-        "   hp_code_rate,    lp_code_rate,      guard_interval) "
-        "VALUES "
-        "  (:SOURCEID,       :SISTANDARD,       :FREQUENCY, "
-        "   :MODULATION,     :TRANSPORTID,      :NETWORKID, "
-        "   :SYMBOLRATE,     :BANDWIDTH,        :POLARITY,  "
-        "   :INVERSION,      :TRANS_MODE,                   "
-        "   :INNER_FEC,      :CONSTELLATION,    :HIERARCHY, "
-        "   :HP_CODE_RATE,   :LP_CODE_RATE,     :GUARD_INTERVAL);");
 
     query.bindValue(":SOURCEID",          db_source_id);
     query.bindValue(":SISTANDARD",        sistandard);
@@ -189,18 +168,19 @@
         return 0;
     }
 
-    mplex = get_dtv_multiplex(
-        db_source_id,  sistandard,    frequency,      modulation,
-        // DVB specific
-        transport_id,  network_id,
-        symbol_rate,   bandwidth,     polarity,
-        inversion,     trans_mode,
-        inner_FEC,     constellation, hierarchy,
-        hp_code_rate,  lp_code_rate,  guard_interval);
-
-    VERBOSE(VB_SIPARSER, QString("insert_dtv_multiplex -- ") +
-            QString("inserted %1").arg(mplex));
-
+    if (mplex == 0)
+    {
+        mplex = get_dtv_multiplex(
+            db_source_id,  sistandard,    frequency,      modulation,
+            // DVB specific
+            transport_id,  network_id,
+            symbol_rate,   bandwidth,     polarity,
+            inversion,     trans_mode,
+            inner_FEC,     constellation, hierarchy,
+            hp_code_rate,  lp_code_rate,  guard_interval);
+        VERBOSE(VB_SIPARSER, QString("insert_dtv_multiplex -- ") + 
+            QString("new multiplex %1").arg(mplex));
+    }
     return mplex;
 }
 
@@ -219,7 +199,7 @@
             // DVB specific
             tsid,                 netid,
             -1,                   QChar(cd.BandwidthString()[0]),
-            -1,                   -1,
+            -1,                   'a',
             QChar(cd.TransmissionModeString()[0]),
             QString::null,                  cd.ConstellationString(),
             QChar(cd.HierarchyString()[0]), cd.CodeRateHPString(),
