diff -p -r -u -N -X /tmp/diff.exclude.2720 -x release.20697.0614base -x release.20697.0614c release.20697.0614base/mythtv/libs/libmythtv/dbcheck.cpp release.20697.0614c/mythtv/libs/libmythtv/dbcheck.cpp
--- mythtv/libs/libmythtv/dbcheck.cpp	2009-06-14 05:31:21.000000000 -0500
+++ mythtv/libs/libmythtv/dbcheck.cpp	2009-06-18 17:46:08.000000000 -0500
@@ -1,5 +1,6 @@
 #include <qsqldatabase.h>
 #include <qstring.h>
+#include <qregexp.h>
 
 #include <iostream>
 using namespace std;
@@ -12,10 +13,16 @@ using namespace std;
 #include "dbutil.h"
 #include "videodisplayprofile.h" // for "1214"
 
+// HDHomeRun headers
+#ifdef USING_HDHOMERUN
+#include "hdhomerun_includes.h"
+#endif
+
+
 #define MINIMUM_DBMS_VERSION 5
 
 /// This is the DB schema version expected by the running MythTV instance.
-const QString currentDatabaseVersion = "1215";
+const QString currentDatabaseVersion = "1216";
 
 static bool UpdateDBVersionNumber(const QString &newnumber);
 static bool performActualUpdate(const QString updates[], QString version,
@@ -3634,6 +3641,189 @@ thequery,
             return false;
     }
 
+    if (dbver == "1215")
+    {
+#ifdef USING_HDHOMERUN
+        VERBOSE(VB_IMPORTANT, "In 1215 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]", false);
+        QRegExp newwildcard = QRegExp("F{8}-[0-9]", false); // "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) > 0)
+            {
+                QString new_device = "";
+                if (device.contains(newwildcard) > 0) // 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, false);
+                } else if (device.upper() == 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.upper())
+                                                 .arg(cardid);
+                    VERBOSE(VB_GENERAL, QString("Converting card %1: HDhomerun %2 to %3")
+                                               .arg(cardid).arg(device).arg(new_device.upper()));
+
+                    if (!query2.exec(updatequery))
+                    {
+                       QString msg =
+                             QString("DB Error (Performing database upgrade): \n"
+                                     "Query was: %1 \nError was: %2")
+                                    .arg(updatequery)
+                                    .arg(MythContext::DBErrorMessage(query2.lastError()));
+                        VERBOSE(VB_IMPORTANT, msg);
+                        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, &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.upper())
+                                         .arg(cardid);
+                    VERBOSE(VB_GENERAL, QString("Converting card %1: HDhomerun %2 tuner %3 to %4")
+                                               .arg(cardid).arg(device)
+                                               .arg(tunerid).arg(new_device.upper()));
+                }
+                else
+                {
+                    updatequery = QString("DELETE FROM capturecard "
+                                          "WHERE cardid = %1;")
+                                         .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))
+                {
+                   QString msg =
+                         QString("DB Error (Performing database upgrade): \n"
+                                 "Query was: %1 \nError was: %2")
+                                .arg(updatequery)
+                                .arg(MythContext::DBErrorMessage(query2.lastError()));
+                    VERBOSE(VB_IMPORTANT, msg);
+                    ok = false;
+                }
+            }
+        }
+#endif // USING_HDHOMERUN
+        const QString updates[] = { "" };
+
+        if (!performActualUpdate(updates, "1216", dbver))
+            return false;
+        VERBOSE(VB_IMPORTANT, "DBCheck: done with HDhomerun upgrade");
+    }
 
 
 //"ALTER TABLE cardinput DROP COLUMN preference;" in 0.22
