diff -p -r -u -N -X /tmp/diff.exclude.8482 -x myth.20713.0616a -x myth.20713.0616b myth.20713.0616a/mythtv/libs/libmythtv/dbcheck.cpp myth.20713.0616b/mythtv/libs/libmythtv/dbcheck.cpp
--- mythtv/libs/libmythtv/dbcheck.cpp	2009-06-02 14:48:34.000000000 -0500
+++ mythtv/libs/libmythtv/dbcheck.cpp	2009-06-18 18:04:52.000000000 -0500
@@ -14,11 +14,16 @@ using namespace std;
 #include "mythdb.h"
 #include "mythverbose.h"
 
+// HDHomeRun headers
+#ifdef USING_HDHOMERUN
+#include "hdhomerun.h"
+#endif
+
 
 #define MINIMUM_DBMS_VERSION 5,0,15
 
 /// This is the DB schema version expected by the running MythTV instance.
-const QString currentDatabaseVersion = "1235";
+const QString currentDatabaseVersion = "1236";
 
 static bool UpdateDBVersionNumber(const QString &newnumber);
 static bool performActualUpdate(
@@ -4543,6 +4548,187 @@ NULL
             return false;
     }
 
+    if (dbver == "1235")
+    {
+#ifdef USING_HDHOMERUN
+        VERBOSE(VB_IMPORTANT, "In 1235 upg (HDhomerun tunerid change)");
+
+        // First discover all HDhomreun devices on the network
+        // This will be cached and used to match up with the database query
+
+        uint32_t  target_ip   = 0; // WILDCARD
+        uint32_t  device_type = HDHOMERUN_DEVICE_TYPE_TUNER;
+        uint32_t  device_id   = HDHOMERUN_DEVICE_ID_WILDCARD;
+        const int max_count   = 50;
+        hdhomerun_discover_device_t hdhr_device_list[max_count];
+
+        int hdhr_device_count = hdhomerun_discover_find_devices_custom(
+                                  target_ip,
+                                  device_type,
+                                  device_id,
+                                  hdhr_device_list,
+                                  max_count);
+
+        if (hdhr_device_count == -1)
+        {
+            // Can only check for existing devices
+            VERBOSE(VB_IMPORTANT, "Error finding HDHomerun devices");
+            VERBOSE(VB_IMPORTANT, "All configured HDHomerun devices must be accessible");
+            return false;
+        }
+
+        MSqlQuery query(MSqlQuery::InitCon());
+        query.prepare("SELECT cardid, videodevice, dbox2_port "
+                      "FROM capturecard "
+                      "WHERE cardtype = 'HDHOMERUN' "
+                      "ORDER BY cardid");
+        bool ok = query.exec();
+
+        MSqlQuery query2(MSqlQuery::InitCon());
+        QRegExp newstyle = QRegExp("[0-9A-Z]{8}-[0-9]", Qt::CaseInsensitive);
+        QRegExp newwildcard = QRegExp("F{8}-[0-9]", Qt::CaseInsensitive); // "FFFFFFFF-n"
+
+        while (ok && query.next())
+        {
+            uint    cardid  = query.value(0).toUInt();
+            QString device  = query.value(1).toString();
+            uint    tunerid = query.value(2).toUInt();
+
+            // First check if this is the new style already
+            if (device.contains(newstyle))
+            {
+                QString new_device = "";
+                if (device.contains(newwildcard)) // FFFFFFFF-1
+                {
+                    // Must convert to an actual HDHR
+                    // Use the first HDHR found.
+
+                    QString new_device_id = QString("%1").arg(hdhr_device_list[0].device_id, 8, 16);
+                    new_device = device;
+                    new_device.replace("ffffffff", new_device_id, Qt::CaseInsensitive);
+                } else if (device.toUpper() == device)
+                    VERBOSE(VB_GENERAL, QString("Retaining card %1: HDhomerun %2")
+                                               .arg(cardid).arg(device));
+                else
+                {
+                    // Convert to upper case
+                    new_device = device;
+                }
+
+                if (new_device.length() > 0)
+                {
+                    QString updatequery = QString("UPDATE capturecard SET videodevice = '%1' "
+                                                  "WHERE cardid = %2;")
+                                                 .arg(new_device.toUpper())
+                                                 .arg(cardid);
+                    VERBOSE(VB_GENERAL, QString("Converting card %1: HDhomerun %2 to %3")
+                                               .arg(cardid).arg(device).arg(new_device.toUpper()));
+
+                    if (!query2.exec(updatequery))
+                    {
+                        MythDB::DBError(
+                            "Could not perform update for '1236'", query2);
+                        ok = false;
+                    }
+                }
+            }
+            else
+            {
+
+                // change from device, tuner to device-tuner
+                // i.e.:  AABBCCDD, 1 -> AABBCCDD-1
+                // If device is xxxxxxxx then use it directly
+                // If device is FFFFFFFF then try to discover the HDHR to get the actual value
+                // If device is x.x.x.x (ip address) then try to discover the HDHR to get the actual value
+
+                bool    valid;
+                uint    device_id = device.toUInt(&valid, 16);
+
+                QString new_device = "";
+                if (valid && device_id != HDHOMERUN_DEVICE_ID_WILDCARD
+                          && hdhomerun_discover_validate_device_id(device_id))
+                {
+                    // Valid, non-wildcard device id
+                    // Update it to "xxxxxxxx-#"
+                    new_device = QString("%1-%2").arg(device).arg(tunerid);
+
+                }
+                else if (valid && device_id == HDHOMERUN_DEVICE_ID_WILDCARD)
+                {
+                    // Use the first HDHR found.  It should be the only one if this
+                    // worked before.
+
+                    new_device = QString("%1-%2")
+                                         .arg(hdhr_device_list[0].device_id, 8, 16)
+                                         .arg(tunerid);
+                }
+                else
+                {
+
+                    // Check for IP address;
+
+                    struct in_addr address;
+                    uint tmp_device_ip;
+                    if (inet_aton(device.toUtf8(), &address))
+                    {
+                        tmp_device_ip = ntohl(address.s_addr);
+                        int i;
+                        for (i = 0; i < hdhr_device_count; i++)
+                        {
+                            if (tmp_device_ip == hdhr_device_list[i].ip_addr)
+                            {
+                                new_device = QString("%1-%2")
+                                                     .arg(hdhr_device_list[1].device_id, 8, 16)
+                                                     .arg(tunerid);
+                                break;
+                            }
+                        }
+                    }
+                }
+
+                // If we identified the HDhomerun device, update it.
+                // Otherwise delete it
+
+                QString updatequery;
+                if (new_device.length() > 0)
+                {
+                    updatequery = QString("UPDATE capturecard SET videodevice = '%1', dbox2_port = 31338 "
+                                          "WHERE cardid = %2;")
+                                         .arg(new_device.toUpper())
+                                         .arg(cardid);
+                    VERBOSE(VB_GENERAL, QString("Converting card %1: HDhomerun %2 tuner %3 to %4")
+                                               .arg(cardid).arg(device)
+                                               .arg(tunerid).arg(new_device.toUpper()));
+                }
+                else
+                {
+                    updatequery = QString("DELETE FROM capturecard "
+                                          "WHERE cardid = %1;"
+                                          "AND dbox2_port = %2;")
+                                         .arg(cardid);
+                    VERBOSE(VB_IMPORTANT, QString("Couldn't find card %1: HDHomerun %2 tuner %3 - deleting")
+                                                 .arg(cardid).arg(device).arg(tunerid));
+                }
+    
+                if (!query2.exec(updatequery))
+                {
+                    MythDB::DBError(
+                        "Could not perform update for '1236'", query2);
+                    ok = false;
+                }
+            }
+        }
+
+        if (!ok)
+            return false;
+
+#endif // USING_HDHOMERUN
+        const char * updates[] = { NULL };
+
+        if (!performActualUpdate(updates, "1236", dbver))
+            return false;
+        VERBOSE(VB_IMPORTANT, "DBCheck: done with HDhomerun upgrade");
+    }
 
     return true;
 }
