Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/mythtv/libs/libmythbase/mythdbcon.cpp b/mythtv/libs/libmythbase/mythdbcon.cpp
- index 6bdcb09..560c0c8 100644
- --- a/mythtv/libs/libmythbase/mythdbcon.cpp
- +++ b/mythtv/libs/libmythbase/mythdbcon.cpp
- @@ -55,7 +55,7 @@ bool MSqlDatabase::isOpen()
- return false;
- }
- -bool MSqlDatabase::OpenDatabase()
- +bool MSqlDatabase::OpenDatabase(bool skipdb)
- {
- if (!m_db.isValid())
- {
- @@ -68,44 +68,45 @@ bool MSqlDatabase::OpenDatabase()
- if (!m_db.isOpen())
- {
- - DatabaseParams dbparms = GetMythDB()->GetDatabaseParams();
- - m_db.setDatabaseName(dbparms.dbName);
- - m_db.setUserName(dbparms.dbUserName);
- - m_db.setPassword(dbparms.dbPassword);
- - m_db.setHostName(dbparms.dbHostName);
- + if (!skipdb)
- + m_dbparms = GetMythDB()->GetDatabaseParams();
- + m_db.setDatabaseName(m_dbparms.dbName);
- + m_db.setUserName(m_dbparms.dbUserName);
- + m_db.setPassword(m_dbparms.dbPassword);
- + m_db.setHostName(m_dbparms.dbHostName);
- - if (dbparms.dbHostName.isEmpty()) // Bootstrapping without a database?
- + if (m_dbparms.dbHostName.isEmpty()) // Bootstrapping without a database?
- {
- connected = true; // Pretend to be connected
- return true; // to reduce errors
- }
- - if (dbparms.dbPort)
- - m_db.setPort(dbparms.dbPort);
- + if (m_dbparms.dbPort)
- + m_db.setPort(m_dbparms.dbPort);
- - if (dbparms.dbPort && dbparms.dbHostName == "localhost")
- + if (m_dbparms.dbPort && m_dbparms.dbHostName == "localhost")
- m_db.setHostName("127.0.0.1");
- connected = m_db.open();
- - if (!connected && dbparms.wolEnabled)
- + if (!connected && m_dbparms.wolEnabled)
- {
- int trycount = 0;
- - while (!connected && trycount++ < dbparms.wolRetry)
- + while (!connected && trycount++ < m_dbparms.wolRetry)
- {
- VERBOSE(VB_GENERAL, QString(
- "Using WOL to wakeup database server (Try %1 of %2)")
- - .arg(trycount).arg(dbparms.wolRetry));
- + .arg(trycount).arg(m_dbparms.wolRetry));
- - if (myth_system(dbparms.wolCommand) != GENERIC_EXIT_OK)
- + if (myth_system(m_dbparms.wolCommand) != GENERIC_EXIT_OK)
- {
- VERBOSE(VB_IMPORTANT,
- QString("Failed to run WOL command '%1'")
- - .arg(dbparms.wolCommand));
- + .arg(m_dbparms.wolCommand));
- }
- - sleep(dbparms.wolReconnect);
- + sleep(m_dbparms.wolReconnect);
- connected = m_db.open();
- }
- @@ -139,6 +140,22 @@ bool MSqlDatabase::OpenDatabase()
- return connected;
- }
- +bool MSqlDatabase::TestDatabase(QString dbHostName,
- + QString dbUserName,
- + QString dbPassword,
- + QString dbName)
- +{
- + if (dbHostName.isEmpty() || dbUserName.isEmpty())
- + return false;
- +
- + m_dbparms.dbName = dbName;
- + m_dbparms.dbUserName = dbUserName;
- + m_dbparms.dbPassword = dbPassword;
- + m_dbparms.dbHostName = dbHostName;
- +
- + return OpenDatabase(true);
- +}
- +
- bool MSqlDatabase::KickDatabase()
- {
- // Some explanation is called for. This exists because the mysql
- diff --git a/mythtv/libs/libmythbase/mythdbcon.h b/mythtv/libs/libmythbase/mythdbcon.h
- index 77fad59..b30f87e 100644
- --- a/mythtv/libs/libmythbase/mythdbcon.h
- +++ b/mythtv/libs/libmythbase/mythdbcon.h
- @@ -10,6 +10,7 @@
- #include <QList>
- #include "mythbaseexp.h"
- +#include "mythdbparams.h"
- class QSemaphore;
- @@ -24,7 +25,19 @@ class MBASE_PUBLIC MSqlDatabase
- private:
- bool isOpen(void);
- - bool OpenDatabase(void);
- + bool OpenDatabase(bool skipdb = false);
- + bool TestDatabase(QString dbHostName,
- + QString dbUserName,
- + QString dbPassword,
- + QString dbName = "mythconverg");
- +/* int dbPort = 0,
- + bool localEnabled = false,
- + QString localHostName = "localhost",
- + bool wolEnabled = false,
- + int wolReconnect = 3,
- + int wolRetry = 10,
- + QString wolCommand = QString(),
- + bool dbHostPing = true);*/
- bool KickDatabase(void);
- QString GetConnectionName(void) const { return m_name; }
- QSqlDatabase db(void) const { return m_db; }
- @@ -34,6 +47,7 @@ class MBASE_PUBLIC MSqlDatabase
- QString m_name;
- QSqlDatabase m_db;
- QDateTime m_lastDBKick;
- + DatabaseParams m_dbparms;
- };
- /// \brief DB connection pool, used by MSqlQuery. Do not use directly.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement