Backports 063e45ed23 , 4dfcdb8dd , and 1fb0a77fc from master.

Corrects one additional addBindValue() in ProgramInfo::QueryDVDBookmark that no longer exists in master.


---
 mythplugins/mythmusic/mythmusic/smartplaylist.cpp     |    2 	1 +	1 -	0 !
 mythplugins/mythweather/mythweather/weatherSource.cpp |    6 	3 +	3 -	0 !
 mythtv/libs/libmyth/programinfo.cpp                   |   28 	14 +	14 -	0 !
 mythtv/libs/libmythdb/mythdb.cpp                      |    2 	1 +	1 -	0 !
 mythtv/libs/libmythdb/mythdb.h                        |    5 	3 +	2 -	0 !
 mythtv/libs/libmythdb/mythdbcon.cpp                   |  201 	121 +	80 -	0 !
 mythtv/libs/libmythdb/mythdbcon.h                     |   54 	47 +	7 -	0 !
 mythtv/libs/libmythdb/mythversion.h                   |    2 	1 +	1 -	0 !
 mythtv/libs/libmythtv/datadirect.cpp                  |    3 	1 +	2 -	0 !
 mythtv/libs/libmythtv/dbcheck.cpp                     |    8 	4 +	4 -	0 !
 mythtv/programs/mythbackend/httpstatus.cpp            |    9 	3 +	6 -	0 !
 mythtv/programs/mythbackend/main_helpers.cpp          |   12 	5 +	7 -	0 !
 mythtv/programs/mythbackend/mainserver.cpp            |    8 	3 +	5 -	0 !
 mythtv/programs/mythbackend/scheduler.cpp             |    4 	2 +	2 -	0 !
 mythtv/programs/mythfrontend/progfind.cpp             |    2 	1 +	1 -	0 !
 15 files changed, 210 insertions(+), 136 deletions(-)

Index: mythtv/mythtv/libs/libmyth/programinfo.cpp
===================================================================
--- mythtv.orig/mythtv/libs/libmyth/programinfo.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmyth/programinfo.cpp	2011-08-04 23:33:09.000000000 -0400
@@ -2216,8 +2216,8 @@ QStringList ProgramInfo::QueryDVDBookmar
     {
         query.prepare(" SELECT title, framenum, audionum, subtitlenum "
                         " FROM dvdbookmark "
-                        " WHERE serialid = ? ");
-        query.addBindValue(serialid);
+                        " WHERE serialid = :SERIALID ");
+        query.bindValue(":SERIALID", serialid);
 
         if (query.exec() && query.next())
         {
@@ -2231,8 +2231,8 @@ QStringList ProgramInfo::QueryDVDBookmar
         int days = -(gCoreContext->GetNumSetting("DVDBookmarkDays", 10));
         QDateTime removedate = mythCurrentDateTime().addDays(days);
         query.prepare(" DELETE from dvdbookmark "
-                        " WHERE timestamp < ? ");
-        query.addBindValue(removedate.toString(Qt::ISODate));
+                        " WHERE timestamp < :REMOVEDATE ");
+        query.bindValue(":REMOVEDATE", removedate.toString(Qt::ISODate));
 
         if (!query.exec())
             MythDB::DBError("GetDVDBookmark deleting old entries", query);
@@ -2263,17 +2263,17 @@ void ProgramInfo::SaveDVDBookmark(const 
         MythDB::DBError("SetDVDBookmark inserting", query);
 
     query.prepare(" UPDATE dvdbookmark "
-                    " SET title       = ? , "
-                    "     audionum    = ? , "
-                    "     subtitlenum = ? , "
-                    "     framenum    = ? , "
+                    " SET title       = :TITLE , "
+                    "     audionum    = :AUDIONUM , "
+                    "     subtitlenum = :SUBTITLENUM , "
+                    "     framenum    = :FRAMENUM , "
                     "     timestamp   = NOW() "
-                    " WHERE serialid = ? ;");
-    query.addBindValue(title);
-    query.addBindValue(audionum);
-    query.addBindValue(subtitlenum);
-    query.addBindValue(frame);
-    query.addBindValue(serialid);
+                    " WHERE serialid = :SERIALID");
+    query.bindValue(":TITLE",title);
+    query.bindValue(":AUDIONUM",audionum);
+    query.bindValue(":SUBTITLENUM",subtitlenum);
+    query.bindValue(":FRAMENUM",frame);
+    query.bindValue(":SERIALID",serialid);
 
     if (!query.exec())
         MythDB::DBError("SetDVDBookmark updating", query);
Index: mythtv/mythtv/libs/libmythdb/mythdb.cpp
===================================================================
--- mythtv.orig/mythtv/libs/libmythdb/mythdb.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythdb/mythdb.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -158,7 +158,7 @@ QString MythDB::toCommaList(const QMap<Q
     return str;
 }
 
-void MythDB::DBError(const QString &where, const QSqlQuery& query)
+void MythDB::DBError(const QString &where, const MSqlQuery& query)
 {
     QString str = QString("DB Error (%1):\n").arg(where);
 
Index: mythtv/mythtv/libs/libmythdb/mythdb.h
===================================================================
--- mythtv.orig/mythtv/libs/libmythdb/mythdb.h	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythdb/mythdb.h	2011-08-04 23:18:39.000000000 -0400
@@ -14,12 +14,13 @@ class MDBManager;
 
 class MPUBLIC MythDB
 {
+    friend class MSqlQuery;
   public:
     MDBManager *GetDBManager(void);
     Settings *GetOldSettings(void);
 
-    static void DBError(const QString &where, const QSqlQuery &query);
-    static QString DBErrorMessage(const QSqlError& err);
+    static void DBError(const QString &where, const MSqlQuery &query);
+    static QString DBErrorMessage(const QSqlError &err);
 
     DatabaseParams GetDatabaseParams(void) const;
     void SetDatabaseParams(const DatabaseParams &params);
Index: mythtv/mythtv/libs/libmythdb/mythdbcon.cpp
===================================================================
--- mythtv.orig/mythtv/libs/libmythdb/mythdbcon.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythdb/mythdbcon.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -15,6 +15,11 @@
 #include "mythdb.h"
 #include "mythverbose.h"
 
+#define DEBUG_RECONNECT 0
+#if DEBUG_RECONNECT
+#include <stdlib.h>
+#endif
+
 static const uint kPurgeTimeout = 60 * 60;
 
 MSqlDatabase::MSqlDatabase(const QString &name)
@@ -158,51 +163,14 @@ bool MSqlDatabase::OpenDatabase()
     return connected;
 }
 
-bool MSqlDatabase::KickDatabase()
+bool MSqlDatabase::KickDatabase(void)
 {
-    // Some explanation is called for.  This exists because the mysql
-    // driver does not gracefully handle the situation where a TCP
-    // socketconnection is dropped (for example due to a timeout).  If
-    // a Unix domain socket connection is lost, the driver
-    // transparently reestablishes the connection and we don't even
-    // notice.  However, when this happens with a TCP connection, the
-    // driver returns an error for the next query to be executed, and
-    // THEN reestablishes the connection (so the second query succeeds
-    // with no intervention).
-    // mdz, 2003/08/11
-
-
-    if (m_lastDBKick.secsTo(QDateTime::currentDateTime()) < 30 &&
-        m_db.isOpen())
-    {
-        return true;
-    }
-
-    QString query("SELECT NULL;");
-    for (unsigned int i = 0 ; i < 2 ; ++i, usleep(50000))
-    {
-        if (m_db.isOpen())
-        {
-            QSqlQuery result = m_db.exec(query); // don't convert to MSqlQuery
-            if (result.isActive())
-            {
-                m_lastDBKick = QDateTime::currentDateTime();
-                return true;
-            }
-        }
-
-        if (i == 0)
-        {
-            m_db.close();
-            m_db.open();
-        }
-        else
-            VERBOSE(VB_IMPORTANT, MythDB::DBErrorMessage(m_db.lastError()));
-    }
-
     m_lastDBKick = QDateTime::currentDateTime().addSecs(-60);
 
-    return false;
+    if (!m_db.isOpen())
+        m_db.open();
+
+    return m_db.isOpen();
 }
 
 bool MSqlDatabase::Reconnect()
@@ -503,9 +471,31 @@ MSqlQueryInfo MSqlQuery::DDCon()
 
 bool MSqlQuery::exec()
 {
+    if (!m_db)
+    {
+        // Database structure's been deleted
+        return false;
+    }
+
+    if (m_last_prepared_query.isEmpty())
+    {
+        VERBOSE(VB_IMPORTANT,
+            "MSqlQuery::exec(void) called without a prepared query.");
+        return false;
+    }
+
+#if DEBUG_RECONNECT
+    if (random() < RAND_MAX / 50)
+    {
+        VERBOSE(VB_IMPORTANT,
+            "MSqlQuery disconnecting DB to test reconnection logic");
+        m_db->m_db.close();
+    }
+#endif
+
     // Database connection down.  Try to restart it, give up if it's still
     // down
-    if (!m_db->isOpen() && !m_db->Reconnect())
+    if (!m_db->isOpen() && !Reconnect())
     {
         VERBOSE(VB_IMPORTANT, "MySQL server disconnected");
         return false;
@@ -516,7 +506,7 @@ bool MSqlQuery::exec()
     // if the query failed with "MySQL server has gone away"
     // Close and reopen the database connection and retry the query if it
     // connects again
-    if (!result && QSqlQuery::lastError().number() == 2006 && m_db->Reconnect())
+    if (!result && QSqlQuery::lastError().number() == 2006 && Reconnect())
         result = QSqlQuery::exec();
 
     if (VERBOSE_LEVEL_CHECK(VB_DATABASE))
@@ -547,9 +537,15 @@ bool MSqlQuery::exec()
 
 bool MSqlQuery::exec(const QString &query)
 {
+    if (!m_db)
+    {
+        // Database structure's been deleted
+        return false;
+    }
+
     // Database connection down.  Try to restart it, give up if it's still
     // down
-    if (!m_db->isOpen() && !m_db->Reconnect())
+    if (!m_db->isOpen() && !Reconnect())
     {
         VERBOSE(VB_IMPORTANT, "MySQL server disconnected");
         return false;
@@ -560,7 +556,7 @@ bool MSqlQuery::exec(const QString &quer
     // if the query failed with "MySQL server has gone away"
     // Close and reopen the database connection and retry the query if it
     // connects again
-    if (!result && QSqlQuery::lastError().number() == 2006 && m_db->Reconnect())
+    if (!result && QSqlQuery::lastError().number() == 2006 && Reconnect())
         result = QSqlQuery::exec(query);
 
     VERBOSE(VB_DATABASE,
@@ -573,35 +569,77 @@ bool MSqlQuery::exec(const QString &quer
     return result;
 }
 
-bool MSqlQuery::next()
+bool MSqlQuery::seekDebug(const char *type, bool result,
+                          int where, bool relative) const
 {
-    bool result = QSqlQuery::next();
-
     if (result && VERBOSE_LEVEL_CHECK(VB_DATABASE|VB_EXTRA))
     {
         QString str;
-        QSqlRecord record=QSqlQuery::record();
+        QSqlRecord rec = record();
 
-        for ( long int i = 0; i<record.count(); i++ )
+        for (long int i = 0; i < rec.count(); i++)
         {
             if (!str.isEmpty())
                 str.append(", ");
 
-            str.append(record.fieldName(i) + " = " + value(i).toString());
+            str.append(rec.fieldName(i) + " = " +
+                       value(i).toString());
         }
 
-        VERBOSE(VB_DATABASE+VB_EXTRA,
-                QString("MSqlQuery::next(%1) Result: \"%2\"")
-                        .arg(m_db->MSqlDatabase::GetConnectionName())
-                        .arg(str));
+        if (QString("seek")==type)
+        {
+            VERBOSE(VB_DATABASE+VB_EXTRA,
+                QString("MSqlQuery::seek(%1,%2,%3) Result: \"%4\"")
+                .arg(m_db->MSqlDatabase::GetConnectionName())
+                .arg(where).arg(relative)
+                .arg(str));
+        }
+        else
+        {
+            VERBOSE(VB_DATABASE+VB_EXTRA,
+                QString("MSqlQuery::%1(%2) Result: \"%3\"")
+                .arg(type).arg(m_db->MSqlDatabase::GetConnectionName())
+                .arg(str));
+        }
     }
-
     return result;
 }
 
+bool MSqlQuery::next(void)
+{
+    return seekDebug("next", QSqlQuery::next(), 0, false);
+}
+
+bool MSqlQuery::previous(void)
+{
+    return seekDebug("previous", QSqlQuery::previous(), 0, false);
+}
+
+bool MSqlQuery::first(void)
+{
+    return seekDebug("first", QSqlQuery::first(), 0, false);
+}
+
+bool MSqlQuery::last(void)
+{
+    return seekDebug("last", QSqlQuery::last(), 0, false);
+}
+
+bool MSqlQuery::seek(int where, bool relative)
+{
+    return seekDebug("seek", QSqlQuery::seek(where, relative), where, relative);
+}
+
 bool MSqlQuery::prepare(const QString& query)
 {
+    if (!m_db)
+    {
+        // Database structure's been deleted
+        return false;
+    }
+
     m_last_prepared_query = query;
+
 #ifdef DEBUG_QT4_PORT
     if (query.contains(m_testbindings))
     {
@@ -614,7 +652,13 @@ bool MSqlQuery::prepare(const QString& q
 
     // Database connection down.  Try to restart it, give up if it's still
     // down
-    if (!m_db->isOpen() && !m_db->Reconnect())
+    if (!m_db)
+    {
+       // Database structure has been deleted...
+        return false;
+    }
+
+    if (!m_db->isOpen() && !Reconnect())
     {
         VERBOSE(VB_IMPORTANT, "MySQL server disconnected");
         return false;
@@ -625,7 +669,7 @@ bool MSqlQuery::prepare(const QString& q
     // if the prepare failed with "MySQL server has gone away"
     // Close and reopen the database connection and retry the query if it
     // connects again
-    if (!ok && QSqlQuery::lastError().number() == 2006 && m_db->Reconnect())
+    if (!ok && QSqlQuery::lastError().number() == 2006 && Reconnect())
         ok = QSqlQuery::prepare(query);
 
     if (!ok && !(GetMythDB()->SuppressDBMessages()))
@@ -649,8 +693,7 @@ bool MSqlQuery::testDBConnection()
     return isOpen;
 }
 
-void MSqlQuery::bindValue (const QString  & placeholder,
-                           const QVariant & val, QSql::ParamType paramType)
+void MSqlQuery::bindValue(const QString &placeholder, const QVariant &val)
 {
 #ifdef DEBUG_QT4_PORT
     // XXX - HACK BEGIN
@@ -665,28 +708,12 @@ void MSqlQuery::bindValue (const QString
     // XXX - HACK END
 #endif
 
-    if (val.type() == QVariant::String && val.isNull())
-    {
-        QSqlQuery::bindValue(placeholder, QString(""), paramType);
-        return;
-    }
-    QSqlQuery::bindValue(placeholder, val, paramType);
+    QSqlQuery::bindValue(placeholder, val, QSql::In);
 }
 
-void MSqlQuery::bindValue(int pos, const QVariant & val,
-                                   QSql::ParamType  paramType)
+void MSqlQuery::bindValues(const MSqlBindings &bindings)
 {
-    if (val.type() == QVariant::String && val.isNull())
-    {
-        QSqlQuery::bindValue(pos, QString(""), paramType);
-        return;
-    }
-    QSqlQuery::bindValue(pos, val, paramType);
-}
-
-void MSqlQuery::bindValues(MSqlBindings &bindings)
-{
-    MSqlBindings::Iterator it;
+    MSqlBindings::const_iterator it;
     for (it = bindings.begin(); it != bindings.end(); ++it)
     {
         bindValue(it.key(), it.value());
@@ -698,6 +725,20 @@ QVariant MSqlQuery::lastInsertId()
     return QSqlQuery::lastInsertId();
 }
 
+bool MSqlQuery::Reconnect(void)
+{
+    if (!m_db->Reconnect())
+        return false;
+    if (!m_last_prepared_query.isEmpty())
+    {
+        MSqlBindings tmp = QSqlQuery::boundValues();
+        if (!prepare(m_last_prepared_query))
+            return false;
+        bindValues(tmp);
+    }
+    return true;
+}
+
 void MSqlAddMoreBindings(MSqlBindings &output, MSqlBindings &addfrom)
 {
     MSqlBindings::Iterator it;
Index: mythtv/mythtv/libs/libmythdb/mythdbcon.h
===================================================================
--- mythtv.orig/mythtv/libs/libmythdb/mythdbcon.h	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythdb/mythdbcon.h	2011-08-04 23:18:39.000000000 -0400
@@ -2,6 +2,8 @@
 #define MYTHDBCON_H_
 
 #include <QSqlDatabase>
+#include <QSqlRecord>
+#include <QSqlError>
 #include <QVariant>
 #include <QSqlQuery>
 #include <QRegExp>
@@ -14,7 +16,7 @@
 class QSemaphore;
 
 /// \brief QSqlDatabase wrapper, used by MSqlQuery. Do not use directly.
-class MPUBLIC MSqlDatabase
+class MSqlDatabase
 {
   friend class MDBManager;
   friend class MSqlQuery;
@@ -101,8 +103,9 @@ MPUBLIC void MSqlEscapeAsAQuery(QString 
  *   will crash if closed and reopend - so we never close them and keep them in
  *   a pool.
  */
-class MPUBLIC MSqlQuery : public QSqlQuery
+class MPUBLIC MSqlQuery : private QSqlQuery
 {
+    friend void MSqlEscapeAsAQuery(QString&, MSqlBindings&);
   public:
     /// \brief Get DB connection from pool
     MSqlQuery(const MSqlQueryInfo &qi);
@@ -118,19 +121,29 @@ class MPUBLIC MSqlQuery : public QSqlQue
     /// \brief Wrap QSqlQuery::next() so we can display the query results
     bool next(void);
 
+    /// \brief Wrap QSqlQuery::previous() so we can display the query results
+    bool previous(void);
+
+    /// \brief Wrap QSqlQuery::first() so we can display the query results
+    bool first(void);
+
+    /// \brief Wrap QSqlQuery::last() so we can display the query results
+    bool last(void);
+
+    /// \brief Wrap QSqlQuery::seek(int,bool)
+    //         so we can display the query results
+    bool seek(int, bool relative = false);
+
     /// \brief Wrap QSqlQuery::exec(const QString &query) so we can display SQL
     bool exec(const QString &query);
 
     /// \brief QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2
     bool prepare(const QString &query);
 
-    /// \brief Wrap QSqlQuery::bindValue so we can convert null QStrings to empty QStrings
-    void bindValue ( const QString & placeholder, const QVariant & val, QSql::ParamType paramType = QSql::In );
-    /// \brief Wrap QSqlQuery::bindValue so we can convert null QStrings to empty QStrings
-    void bindValue ( int pos, const QVariant & val, QSql::ParamType paramType = QSql::In );
+    void bindValue(const QString &placeholder, const QVariant &val);
 
     /// \brief Add all the bindings in the passed in bindings
-    void bindValues(MSqlBindings &bindings);
+    void bindValues(const MSqlBindings &bindings);
 
     /** \brief Return the id of the last inserted row
      *
@@ -142,6 +155,25 @@ class MPUBLIC MSqlQuery : public QSqlQue
      */
     QVariant lastInsertId();
 
+    /// Reconnects server and re-prepares and re-binds the last prepared
+    /// query.
+    bool Reconnect(void);
+
+    // Thunks that allow us to make QSqlQuery private
+    QVariant value(int i) const { return QSqlQuery::value(i); }
+    QString executedQuery(void) const { return QSqlQuery::executedQuery(); }
+    QMap<QString, QVariant> boundValues(void) const
+        { return QSqlQuery::boundValues(); }
+    QSqlError lastError(void) const { return QSqlQuery::lastError(); }
+    int size(void) const { return QSqlQuery::size();}
+    bool isActive(void) const { return  QSqlQuery::isActive(); }
+    QSqlRecord record(void) const { return QSqlQuery::record(); }
+    int numRowsAffected() const { return QSqlQuery::numRowsAffected(); }
+    void setForwardOnly(bool f) { QSqlQuery::setForwardOnly(f); }
+    bool isNull(int field) const { return QSqlQuery::isNull(field); }
+    const QSqlDriver *driver(void) const { return QSqlQuery::driver(); }
+    int at(void) const { return QSqlQuery::at(); }
+
     /// \brief Checks DB connection + login (login info via Mythcontext)
     static bool testDBConnection();
 
@@ -155,6 +187,14 @@ class MPUBLIC MSqlQuery : public QSqlQue
     static MSqlQueryInfo DDCon();
 
   private:
+    // Only QSql::In is supported as a param type and only named params...
+    void bindValue(const QString&, const QVariant&, QSql::ParamType);
+    void bindValue(int, const QVariant&, QSql::ParamType);
+    void addBindValue(const QVariant&, QSql::ParamType = QSql::In);
+
+    bool seekDebug(const char *type, bool result,
+                   int where, bool relative) const;
+
     MSqlDatabase *m_db;
     bool m_isConnected;
     bool m_returnConnection;
Index: mythtv/mythtv/libs/libmythdb/mythversion.h
===================================================================
--- mythtv.orig/mythtv/libs/libmythdb/mythversion.h	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythdb/mythversion.h	2011-08-04 23:18:39.000000000 -0400
@@ -11,7 +11,7 @@
 /// Update this whenever the plug-in API changes.
 /// Including changes in the libmythdb, libmyth, libmythtv, libmythav* and
 /// libmythui class methods used by plug-ins.
-#define MYTH_BINARY_VERSION "0.24.20110505-1"
+#define MYTH_BINARY_VERSION "0.24.20110804-1"
 
 /** \brief Increment this whenever the MythTV network protocol changes.
  *
Index: mythtv/mythtv/libs/libmythtv/datadirect.cpp
===================================================================
--- mythtv.orig/mythtv/libs/libmythtv/datadirect.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythtv/datadirect.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -822,8 +822,7 @@ bool DataDirectProcessor::UpdateChannels
 
         if (!chan_update_q.exec())
         {
-            MythDB::DBError("Updating channel table",
-                            chan_update_q.lastQuery());
+            MythDB::DBError("Updating channel table", chan_update_q);
         }
     }
 
Index: mythtv/mythtv/libs/libmythtv/dbcheck.cpp
===================================================================
--- mythtv.orig/mythtv/libs/libmythtv/dbcheck.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/libs/libmythtv/dbcheck.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -3659,7 +3659,7 @@ NULL
             {
                 MythDB::DBError(QString("Unable to perform test for database "
                                 "corruption before character set conversion."),
-                                thequery);
+                                query);
                 return false;
             }
             // If the conversion to utf8 resulted in warnings, the data in the
@@ -3688,7 +3688,7 @@ NULL
             {
                 MythDB::DBError(QString("Error getting database warnings for "
                                 "database corruption test."),
-                                thequery);
+                                query);
                 return false;
             }
             // Test creating an index to see if we had partial corruption that
@@ -3702,7 +3702,7 @@ NULL
                 if (!ok)
                 {
                     MythDB::DBError(QString("Index creation failed."),
-                                    thequery);
+                                    query);
                     VERBOSE(VB_IMPORTANT, "DB charset pre-conversion test "
                             "failed! Your database seems to be partially "
                             "corrupted. Please move the backup to a safe "
@@ -3716,7 +3716,7 @@ NULL
             thequery = QString("DROP TEMPORARY TABLE temp_%1;").arg(table);
             if (!query.exec(thequery))
                 MythDB::DBError(QString("Error dropping temporary table %1.")
-                                .arg(table), thequery);
+                                .arg(table), query);
 
             tableIndex++;
         }
Index: mythtv/mythtv/programs/mythbackend/httpstatus.cpp
===================================================================
--- mythtv.orig/mythtv/programs/mythbackend/httpstatus.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/programs/mythbackend/httpstatus.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -430,13 +430,10 @@ void HttpStatus::FillStatusXML( QDomDocu
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare("SELECT MAX(endtime) FROM program WHERE manualid = 0;");
 
-    if (query.exec() && query.isActive() && query.size())
+    if (query.exec() && query.next())
     {
-        query.next();
-
-        if (query.isValid())
-            GuideDataThrough = QDateTime::fromString(query.value(0).toString(),
-                                                     Qt::ISODate);
+        GuideDataThrough = QDateTime::fromString(
+            query.value(0).toString(), Qt::ISODate);
     }
 
     guide.setAttribute("start", gCoreContext->GetSetting("mythfilldatabaseLastRunStart"));
Index: mythtv/mythtv/programs/mythbackend/main_helpers.cpp
===================================================================
--- mythtv.orig/mythtv/programs/mythbackend/main_helpers.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/programs/mythbackend/main_helpers.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -75,15 +75,14 @@ bool setupTVs(bool ismaster, bool &error
                         "DATE_FORMAT(starttime, '%Y%m%d%H%i00'), '_', "
                         "DATE_FORMAT(endtime, '%Y%m%d%H%i00'), '.nuv') "
                         "WHERE basename = '';"))
-            MythDB::DBError("Updating record basename",
-                                 query.lastQuery());
+            MythDB::DBError("Updating record basename", query);
 
         // Hack to make sure record.station gets set if the user
         // downgrades to a prior version and creates new entries
         // without it.
         if (!query.exec("UPDATE channel SET callsign=chanid "
                         "WHERE callsign IS NULL OR callsign='';"))
-            MythDB::DBError("Updating channel callsign", query.lastQuery());
+            MythDB::DBError("Updating channel callsign", query);
 
         if (query.exec("SELECT MIN(chanid) FROM channel;"))
         {
@@ -91,10 +90,10 @@ bool setupTVs(bool ismaster, bool &error
             int min_chanid = query.value(0).toInt();
             if (!query.exec(QString("UPDATE record SET chanid = %1 "
                                     "WHERE chanid IS NULL;").arg(min_chanid)))
-                MythDB::DBError("Updating record chanid", query.lastQuery());
+                MythDB::DBError("Updating record chanid", query);
         }
         else
-            MythDB::DBError("Querying minimum chanid", query.lastQuery());
+            MythDB::DBError("Querying minimum chanid", query);
 
         MSqlQuery records_without_station(MSqlQuery::InitCon());
         records_without_station.prepare("SELECT record.chanid,"
@@ -113,8 +112,7 @@ bool setupTVs(bool ismaster, bool &error
                         records_without_station.value(0));
                 if (!update_record.exec())
                 {
-                    MythDB::DBError("Updating record station",
-                            update_record.lastQuery());
+                    MythDB::DBError("Updating record station", update_record);
                 }
             } while (records_without_station.next());
         }
Index: mythtv/mythtv/programs/mythbackend/mainserver.cpp
===================================================================
--- mythtv.orig/mythtv/programs/mythbackend/mainserver.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/programs/mythbackend/mainserver.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -2929,12 +2929,10 @@ void MainServer::getGuideDataThrough(QDa
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare("SELECT MAX(endtime) FROM program WHERE manualid = 0;");
 
-    if (query.exec() && query.isActive() && query.size())
+    if (query.exec() && query.next())
     {
-        query.next();
-        if (query.isValid())
-            GuideDataThrough = QDateTime::fromString(query.value(0).toString(),
-                                                     Qt::ISODate);
+        GuideDataThrough = QDateTime::fromString(
+            query.value(0).toString(), Qt::ISODate);
     }
 }
 
Index: mythtv/mythtv/programs/mythbackend/scheduler.cpp
===================================================================
--- mythtv.orig/mythtv/programs/mythbackend/scheduler.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/programs/mythbackend/scheduler.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -3604,12 +3604,12 @@ void Scheduler::AddNewRecords(void)
     {
         result.prepare("DROP TABLE IF EXISTS sched_temp_record;");
         if (!result.exec())
-            MythDB::DBError("AddNewRecords sched_temp_record", query);
+            MythDB::DBError("AddNewRecords sched_temp_record", result);
     }
 
     result.prepare("DROP TABLE IF EXISTS sched_temp_recorded;");
     if (!result.exec())
-        MythDB::DBError("AddNewRecords drop table", query);
+        MythDB::DBError("AddNewRecords drop table", result);
 }
 
 void Scheduler::AddNotListed(void) {
Index: mythtv/mythtv/programs/mythfrontend/progfind.cpp
===================================================================
--- mythtv.orig/mythtv/programs/mythfrontend/progfind.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythtv/programs/mythfrontend/progfind.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -527,7 +527,7 @@ void ProgFinder::getShowNames()
     query.bindValues(bindings);
     if (!query.exec())
     {
-        MythDB::DBError("getShowNames", thequery);
+        MythDB::DBError("getShowNames", query);
         return;
     }
 
Index: mythtv/mythplugins/mythmusic/mythmusic/smartplaylist.cpp
===================================================================
--- mythtv.orig/mythplugins/mythmusic/mythmusic/smartplaylist.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythplugins/mythmusic/mythmusic/smartplaylist.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -1733,7 +1733,7 @@ void SmartPLResultViewer::setSQL(QString
                 query.value(4).toString(),
                 query.value(5).toString(),
                 query.value(6).toString());
-        } while (query.prev());
+        } while (query.previous());
     }
 
     // set selection to first item
Index: mythtv/mythplugins/mythweather/mythweather/weatherSource.cpp
===================================================================
--- mythtv.orig/mythplugins/mythweather/mythweather/weatherSource.cpp	2011-08-04 23:18:24.000000000 -0400
+++ mythtv/mythplugins/mythweather/mythweather/weatherSource.cpp	2011-08-04 23:18:39.000000000 -0400
@@ -304,7 +304,7 @@ ScriptInfo *WeatherSource::ProbeScript(c
             db.bindValue(":EMAIL", info.email);
             if (!db.exec())
             {
-                MythDB::DBError("Updating weather source settings.", query);
+                MythDB::DBError("Updating weather source settings.", db);
                 return NULL;
             }
         }
@@ -338,7 +338,7 @@ ScriptInfo *WeatherSource::ProbeScript(c
         db.bindValue(":TYPES", info.types.join(","));
         if (!db.exec())
         {
-            MythDB::DBError("Inserting weather source", query);
+            MythDB::DBError("Inserting weather source", db);
             return NULL;
         }
         query = "SELECT sourceid FROM weathersourcesettings "
@@ -350,7 +350,7 @@ ScriptInfo *WeatherSource::ProbeScript(c
         db.bindValue(":NAME", info.name);
         if (!db.exec())
         {
-            MythDB::DBError("Getting weather sourceid", query);
+            MythDB::DBError("Getting weather sourceid", db);
             return NULL;
         }
         else if (!db.next())
