Index: programs/mythbackend/housekeeper.cpp
===================================================================
--- programs/mythbackend/housekeeper.cpp	(revision 17077)
+++ programs/mythbackend/housekeeper.cpp	(working copy)
@@ -62,47 +62,51 @@
     QDateTime lastrun;
     lastrun.setTime_t(0);
 
-    if (minhour < 0)
-        minhour = 0;
-    if (maxhour > 23)
-        maxhour = 23;
+    minhour = (minhour < 0)  ? 0  : minhour;
+    maxhour = (maxhour > 23) ? 23 : maxhour;
 
-    MSqlQuery result(MSqlQuery::InitCon());
-    if (result.isConnected())
+    MSqlQuery query(MSqlQuery::InitCon());
+    if (!query.isConnected())
+        return runOK;
+
+    query.prepare("SELECT lastrun FROM housekeeping WHERE tag = :TAG ;");
+    query.bindValue(":TAG", dbTag);
+    bool ok = query.exec();
+
+    if (ok && query.next())
     {
-        result.prepare("SELECT lastrun FROM housekeeping WHERE tag = :TAG ;");
-        result.bindValue(":TAG", dbTag);
+        lastrun = query.value(0).toDateTime();
 
-        if (result.exec() && result.isActive() && result.size() > 0)
+        if ((lastrun.secsTo(now) > longEnough) &&
+            (now.date().day() != lastrun.date().day()))
         {
-            result.next();
-            lastrun = result.value(0).toDateTime();
+            int hour = now.time().hour();
 
-            if ((lastrun.secsTo(now) > longEnough) &&
-                (now.date().day() != lastrun.date().day()))
+            if (((minhour > maxhour) &&
+                 ((hour <= maxhour) || (hour >= minhour))) ||
+                ((hour >= minhour) && (hour <= maxhour)))
             {
-                int hour = now.time().hour();
-
-                if (((minhour > maxhour) &&
-                     ((hour <= maxhour) || (hour >= minhour))) ||
-                    ((hour >= minhour) && (hour <= maxhour)))
+                int minute = now.time().minute();
+                if ((hour == maxhour && minute > 30) ||
+                    ((random()%(((maxhour-hour)*12+
+                                 (60-minute)/5 - 6) + 1)) == 0))
                 {
-                    int minute = now.time().minute();
-                    if ((hour == maxhour && minute > 30) ||
-                        ((random()%(((maxhour-hour)*12+(60-minute)/5 - 6) + 1)) == 0))
                         runOK = true;
                 }
             }
         }
-        else
-        {
-            result.prepare("INSERT INTO housekeeping(tag,lastrun) "
-                           "values(:TAG ,now());");
-            result.bindValue(":TAG", dbTag);
-            result.exec();
+    }
+    else
+    {
+        if (!ok)
+            MythContext::DBError("wantToRun failure", query);
 
-            runOK = true;
-        }
+        query.prepare("INSERT INTO housekeeping(tag,lastrun) "
+                       "VALUES(:TAG ,now());");
+        query.bindValue(":TAG", dbTag);
+        query.exec();
+
+        runOK = true;
     }
 
     return runOK;
@@ -222,9 +226,9 @@
                         QDateTime lastRun = getLastRun("MythFillDB");
                         QDateTime now = QDateTime::currentDateTime();
 
-                        if ((nextRun < now) &&
-                            (lastRun.secsTo(now) > (3 * 60 * 60)))
-                            runMythFill = true;
+                        runMythFill |= ((nextRun < now) &&
+                                        (lastRun.secsTo(now) > (3 * 60 * 60)));
+                            
                     }
                     else if (wantToRun("MythFillDB", period, minhr, maxhr))
                     {
