Index: autoexpire.cpp
===================================================================
--- autoexpire.cpp	(revision 7027)
+++ autoexpire.cpp	(working copy)
@@ -419,37 +419,46 @@
 
         query.prepare(querystr);
 
-        VERBOSE(VB_FILE, QString("Found %1 episodes in recording profile %2 "
-                                 "using max expiration")
-                                 .arg(query.numRowsAffected())
-                                 .arg(maxIter.key()));
-        if (query.exec() && query.isActive() && query.size() > 0)
-        {
-            int found = 0;
-            while (query.next())
-            {
-                found++;
-
-                if (found > maxIter.data())
+        if (query.exec() && query.isActive())
+	{
+            VERBOSE(VB_FILE, QString("Found %1 episodes in recording profile %2 "
+                                     "using max expiration")
+				     .arg(query.numRowsAffected())
+				     .arg(maxIter.key()));
+	    if (query.size() > 0)
+	    {
+                int found = 0;
+                while (query.next())
                 {
-                    QString msg = QString("Expiring \"%1\" from %2, "
-                                          "too many episodes.")
-                                          .arg(query.value(2).toString())
-                                          .arg(query.value(1).toString());
-                    VERBOSE(VB_FILE, msg);
-                    gContext->LogEntry("autoexpire", LP_NOTICE,
-                                       "Expired program", msg);
+                    found++;
 
-                    msg = QString("AUTO_EXPIRE %1 %2")
-                                  .arg(query.value(0).toString())
-                                  .arg(query.value(1).toDateTime()
-                                       .toString(Qt::ISODate));
+                    if (found > maxIter.data())
+		    {
+		        QString msg = QString("Expiring \"%1\" from %2, "
+					      "too many episodes.")
+                                              .arg(query.value(2).toString())
+                                              .arg(query.value(1).toString());
+			VERBOSE(VB_FILE, msg);
+			gContext->LogEntry("autoexpire", LP_NOTICE,
+					   "Expired program", msg);
 
-                    MythEvent me(msg);
-                    gContext->dispatchNow(me);
-                }
+			msg = QString("AUTO_EXPIRE %1 %2")
+				      .arg(query.value(0).toString())
+				      .arg(query.value(1).toDateTime()
+					   .toString(Qt::ISODate));
+
+			MythEvent me(msg);
+			gContext->dispatchNow(me);
+		    }
+		}
             }
         }
+	else
+	{
+            VERBOSE(VB_FILE, QString("Query failed trying to find episodes in "
+                                     "recording profile %1 using max expiration")
+				     .arg(maxIter.key()));
+	}
     }
 }
 
