MythTV  master
dbutil.cpp
Go to the documentation of this file.
1 #include <climits>
2 #include <cstdio>
3 #include <cstdlib>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 
8 #include <QDir>
9 #include <QFile>
10 #include <QRegularExpression>
11 #include <QDateTime>
12 #include <QSqlError>
13 #include <QSqlRecord>
14 
15 #include "dbutil.h"
16 #include "mythcorecontext.h"
17 #include "storagegroup.h"
18 #include "mythmiscutil.h"
19 #include "mythdate.h"
20 #include "mythdb.h"
21 #include "mythdirs.h"
22 #include "mythlogging.h"
23 #include "mythsystemlegacy.h"
24 #include "exitcodes.h"
25 
26 #define LOC QString("DBUtil: ")
27 
28 const int DBUtil::kUnknownVersionNumber = INT_MIN;
29 
35 {
36  if (m_versionString.isEmpty())
38  return m_versionString;
39 }
40 
53 int DBUtil::CompareDBMSVersion(int major, int minor, int point)
54 {
55  if (m_versionMajor < 0)
56  if (!ParseDBMSVersion())
57  return kUnknownVersionNumber;
58 
59  int result = 0;
61  std::array<int,3> compareto {major, minor, point};
62  for (int i = 0; i < 3 && !result; i++)
63  {
64  if ((version[i] > -1) || (compareto[i] != 0))
65  result = version[i] - compareto[i];
66  }
67 
68  return result;
69 }
70 
75 {
76  const QStringList tables = GetTables();
77  const int size = tables.size();
78  // Usually there will be a single table called schemalock, but check for
79  // no tables, also, just in case.
80  return (((size == 1) && (tables.at(0).endsWith(".`schemalock`"))) ||
81  (size == 0));
82 }
83 
89 {
90  QString backupStartTimeStr =
91  gCoreContext->GetSetting("BackupDBLastRunStart");
92  QString backupEndTimeStr = gCoreContext->GetSetting("BackupDBLastRunEnd");
93 
94  if (backupStartTimeStr.isEmpty())
95  {
96  LOG(VB_DATABASE, LOG_ERR, "DBUtil::BackupInProgress(): No start time "
97  "found, database backup is not in progress.");
98  return false;
99  }
100 
101  backupStartTimeStr.replace(" ", "T");
102 
103  QDateTime backupStartTime = MythDate::fromString(backupStartTimeStr);
104  auto backupElapsed = MythDate::secsInPast(backupStartTime);
105 
106  // No end time set
107  if (backupEndTimeStr.isEmpty())
108  {
109  // If DB Backup started less then 10 minutes ago, assume still running
110  if (backupElapsed < 10min)
111  {
112  LOG(VB_DATABASE, LOG_INFO,
113  QString("DBUtil::BackupInProgress(): Found "
114  "database backup start time of %1 which was %2 seconds "
115  "ago, therefore it appears the backup is still running.")
116  .arg(backupStartTimeStr)
117  .arg(backupElapsed.count()));
118  return true;
119  }
120  LOG(VB_DATABASE, LOG_ERR, QString("DBUtil::BackupInProgress(): "
121  "Database backup started at %1, but no end time was found. "
122  "The backup started %2 seconds ago and should have "
123  "finished by now therefore it appears it is not running .")
124  .arg(backupStartTimeStr)
125  .arg(backupElapsed.count()));
126  return false;
127  }
128 
129  backupEndTimeStr.replace(" ", "T");
130 
131  QDateTime backupEndTime = MythDate::fromString(backupEndTimeStr);
132 
133  if (backupEndTime >= backupStartTime)
134  {
135  LOG(VB_DATABASE, LOG_ERR,
136  QString("DBUtil::BackupInProgress(): Found "
137  "database backup end time of %1 later than start time "
138  "of %2, therefore backup is not running.")
139  .arg(backupEndTimeStr).arg(backupStartTimeStr));
140  return false;
141  }
142  if (backupElapsed > 10min)
143  {
144  LOG(VB_DATABASE, LOG_ERR,
145  QString("DBUtil::BackupInProgress(): "
146  "Database backup started at %1, but has not ended yet. "
147  "The backup started %2 seconds ago and should have "
148  "finished by now therefore it appears it is not running")
149  .arg(backupStartTimeStr)
150  .arg(backupElapsed.count()));
151  return false;
152  }
153 
154  // start > end and started less than 10 minutes ago
155  LOG(VB_DATABASE, LOG_INFO, QString("DBUtil::BackupInProgress(): "
156  "Database backup started at %1, and is still running.")
157  .arg(backupStartTimeStr));
158  return true;
159 }
160 
186 MythDBBackupStatus DBUtil::BackupDB(QString &filename, bool disableRotation)
187 {
188  filename = QString();
189 
190 #ifdef _WIN32
191  LOG(VB_GENERAL, LOG_CRIT, "Database backups disabled on Windows.");
192  return kDB_Backup_Disabled;
193 #else
194 
195  if (gCoreContext->GetBoolSetting("DisableAutomaticBackup", false))
196  {
197  LOG(VB_GENERAL, LOG_CRIT,
198  "Database backups disabled. Skipping backup.");
199  return kDB_Backup_Disabled;
200  }
201 
202  if (IsNewDatabase())
203  {
204  LOG(VB_GENERAL, LOG_CRIT, "New database detected. Skipping backup.");
205  return kDB_Backup_Empty_DB;
206  }
207 
208  QString backupScript = GetShareDir() + "mythconverg_backup.pl";
209  backupScript = gCoreContext->GetSetting("DatabaseBackupScript",
210  backupScript);
211 
212  if (!QFile::exists(backupScript))
213  {
214  LOG(VB_GENERAL, LOG_CRIT, QString("Database backup script does "
215  "not exist: %1").arg(backupScript));
216  backupScript.clear();
217  }
218 
219  bool result = false;
221 
223  "BackupDBLastRunStart",
225 
226  if (!backupScript.isEmpty())
227  {
228  result = DoBackup(backupScript, filename, disableRotation);
229  if (!result)
230  LOG(VB_GENERAL, LOG_CRIT, "Script-based database backup failed. "
231  "Retrying with internal backup.");
232  }
233 
234  if (!result)
235  result = DoBackup(filename);
236 
238  "BackupDBLastRunEnd",
240 
241  if (query.isConnected())
242  {
243  QString dbTag("BackupDB");
244  query.prepare("DELETE FROM housekeeping WHERE tag = :TAG ;");
245  query.bindValue(":TAG", dbTag);
246  if (!query.exec())
247  MythDB::DBError("DBUtil::BackupDB", query);
248 
249  query.prepare("INSERT INTO housekeeping(tag,lastrun) "
250  "values(:TAG ,now()) ;");
251  query.bindValue(":TAG", dbTag);
252  if (!query.exec())
253  MythDB::DBError("DBUtil::BackupDB", query);
254  }
255 
256  if (result)
257  return kDB_Backup_Completed;
258 
259  return kDB_Backup_Failed;
260 #endif // _WIN32
261 }
262 
274 bool DBUtil::CheckTables(const bool repair, const QString &options)
275 {
277  if (!query.isConnected())
278  return false;
279 
280  const QStringList all_tables = GetTables(QStringList("MyISAM"));
281 
282  if (all_tables.empty())
283  return true;
284 
285  QString sql = QString("CHECK TABLE %1 %2;").arg(all_tables.join(", "))
286  .arg(options);
287 
288  LOG(VB_GENERAL, LOG_CRIT, "Checking database tables.");
289  if (!query.exec(sql))
290  {
291  MythDB::DBError("DBUtil Checking Tables", query);
292  return false;
293  }
294 
295  QStringList tables = CheckRepairStatus(query);
296  bool result = true;
297  if (!tables.empty())
298  {
299  LOG(VB_GENERAL, LOG_CRIT, QString("Found crashed database table(s): %1")
300  .arg(tables.join(", ")));
301  if (repair)
302  {
303  // If RepairTables() repairs the crashed tables, return true
304  result = RepairTables(tables);
305  }
306  else
307  {
308  result = false;
309  }
310  }
311 
312  return result;
313 }
314 
332 bool DBUtil::RepairTables(const QStringList &tables)
333 {
335  if (!query.isConnected())
336  return false;
337 
338  QString all_tables = tables.join(", ");
339  LOG(VB_GENERAL, LOG_CRIT, QString("Repairing database tables: %1")
340  .arg(all_tables));
341 
342  QString sql = QString("REPAIR TABLE %1;").arg(all_tables);
343  if (!query.exec(sql))
344  {
345  MythDB::DBError("DBUtil Repairing Tables", query);
346  return false;
347  }
348 
349  QStringList bad_tables = CheckRepairStatus(query);
350  bool result = true;
351  if (!bad_tables.empty())
352  {
353  LOG(VB_GENERAL, LOG_CRIT,
354  QString("Unable to repair crashed table(s): %1")
355  .arg(bad_tables.join(", ")));
356  result = false;
357  }
358  return result;
359 }
360 
380 {
381  QStringList tables;
382  QSqlRecord record = query.record();
383  int table_index = record.indexOf("Table");
384  int type_index = record.indexOf("Msg_type");
385  int text_index = record.indexOf("Msg_text");
386  QString table;
387  QString type;
388  QString text;
389  QString previous_table;
390  bool ok = true;
391  while (query.next())
392  {
393  table = query.value(table_index).toString();
394  type = query.value(type_index).toString();
395  text = query.value(text_index).toString();
396  if (table != previous_table)
397  {
398  if (!ok)
399  {
400  tables.append(previous_table);
401  ok = true;
402  }
403  previous_table = table;
404  }
405  // If the final row shows status OK, the table is now good
406  if ("status" == type.toLower() && "ok" == text.toLower())
407  ok = true;
408  else if ("error" == type.toLower() ||
409  ("status" == type.toLower() && "ok" != text.toLower()))
410  ok = false;
411  }
412  // Check the last table in the list
413  if (!ok)
414  tables.append(table);
415  return tables;
416 }
417 
423 QStringList DBUtil::GetTables(const QStringList &engines)
424 {
425  QStringList result;
426 
428  if (!query.isConnected())
429  return result;
430 
431  QString sql = "SELECT CONCAT('`', TABLE_SCHEMA, "
432  " '`.`', TABLE_NAME, "
433  " '`') AS `TABLE_NAME` "
434  " FROM INFORMATION_SCHEMA.TABLES "
435  " WHERE TABLE_SCHEMA = DATABASE() "
436  " AND TABLE_TYPE = 'BASE TABLE'";
437  if (!engines.empty())
438  sql.append(QString(" AND ENGINE IN ('%1')")
439  .arg(engines.join("', '")));
440  if (!query.exec(sql))
441  {
442  MythDB::DBError("DBUtil Finding Tables", query);
443  return result;
444  }
445 
446  while (query.next())
447  {
448  result.append(query.value(0).toString());
449  }
450 
451  return result;
452 }
453 
466 QString DBUtil::CreateBackupFilename(const QString& prefix, const QString& extension)
467 {
469  return QString("%1-%2%3").arg(prefix).arg(time).arg(extension);
470 }
471 
482 {
483  QString directory;
484  StorageGroup sgroup("DB Backups", gCoreContext->GetHostName());
485  QStringList dirList = sgroup.GetDirList();
486  if (!dirList.empty())
487  {
488  directory = sgroup.FindNextDirMostFree();
489 
490  if (!QDir(directory).exists())
491  {
492  LOG(VB_FILE, LOG_INFO, "GetBackupDirectory() - ignoring " +
493  directory + ", using /tmp");
494  directory.clear();
495  }
496  }
497 
498  if (directory.isNull())
499  {
500  // Rather than use kDefaultStorageDir, the default for
501  // FindNextDirMostFree() when no dirs are defined for the StorageGroup,
502  // use /tmp as it's possible that kDefaultStorageDir doesn't exist
503  // and (at least on *nix) less possible that /tmp doesn't exist
504  directory = "/tmp";
505  }
506 
507  return directory;
508 }
509 
519  const QString &privateinfo, QString &filename)
520 {
521  bool ok = true;
522  filename = createTempFile("/tmp/mythtv_db_backup_conf_XXXXXX");
523  const QByteArray tmpfile = filename.toLocal8Bit();
524 
525  FILE *fp = fopen(tmpfile.constData(), "w");
526  if (!fp)
527  {
528  LOG(VB_GENERAL, LOG_ERR, LOC +
529  QString("Unable to create temporary "
530  "configuration file for creating DB backup: %1")
531  .arg(tmpfile.constData()));
532  filename = "";
533  ok = false;
534  }
535  else
536  {
537  if (chmod(tmpfile.constData(), S_IRUSR))
538  {
539  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error changing permissions '%1'")
540  .arg(tmpfile.constData()) + ENO);
541  }
542 
543  QByteArray outarr = privateinfo.toLocal8Bit();
544  fprintf(fp, "%s", outarr.constData());
545 
546  if (fclose(fp))
547  {
548  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error closing '%1'")
549  .arg(tmpfile.constData()) + ENO);
550  }
551  }
552 
553  return ok;
554 }
555 
562 bool DBUtil::DoBackup(const QString &backupScript, QString &filename,
563  bool disableRotation)
564 {
566  QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
567  QString backupDirectory = GetBackupDirectory();
568  QString backupFilename = CreateBackupFilename(dbParams.m_dbName + "-" +
569  dbSchemaVer, ".sql");
570  QString scriptArgs = gCoreContext->GetSetting("BackupDBScriptArgs");
571  QString rotate = "";
572  if (disableRotation)
573  {
574  if (!(scriptArgs.contains("rotate", Qt::CaseInsensitive)))
575  rotate = "rotate=-1";
576  }
577 
578 
579  QString privateinfo =
580  QString("DBHostName=%1\nDBPort=%2\n"
581  "DBUserName=%3\nDBPassword=%4\n"
582  "DBName=%5\nDBSchemaVer=%6\n"
583  "DBBackupDirectory=%7\nDBBackupFilename=%8\n%9\n")
584  .arg(dbParams.m_dbHostName).arg(dbParams.m_dbPort)
585  .arg(dbParams.m_dbUserName).arg(dbParams.m_dbPassword)
586  .arg(dbParams.m_dbName).arg(dbSchemaVer)
587  .arg(backupDirectory).arg(backupFilename).arg(rotate);
588  QString tempDatabaseConfFile;
589  bool hastemp = CreateTemporaryDBConf(privateinfo, tempDatabaseConfFile);
590  if (!hastemp)
591  LOG(VB_GENERAL, LOG_ERR, LOC + "Attempting backup, anyway.");
592 
593  LOG(VB_GENERAL, LOG_ERR, QString("Backing up database with script: '%1'")
594  .arg(backupScript));
595 
596  QString command = backupScript + " " + scriptArgs + " " +
597  tempDatabaseConfFile;
599 
600  if (hastemp)
601  {
602  QByteArray tmpfile = tempDatabaseConfFile.toLocal8Bit();
603  unlink(tmpfile.constData());
604  }
605 
606  if (status != GENERIC_EXIT_OK)
607  {
608  LOG(VB_GENERAL, LOG_ERR, LOC +
609  QString("Error backing up database: %1 (%2)")
610  .arg(command).arg(status));
611  filename = "__FAILED__";
612  return false;
613  }
614 
615  LOG(VB_GENERAL, LOG_CRIT, "Database Backup complete.");
616 
617  QDir dir(backupDirectory, backupFilename + "*");
618  uint numfiles = dir.count();
619  if (numfiles < 1)
620  {
621  // If no file begins with the suggested filename, don't show the backup
622  // filename in the GUI message -- the script probably used some other
623  // filename
624  filename = "";
625  LOG(VB_FILE, LOG_ERR, LOC +
626  QString("No files beginning with the suggested database backup "
627  "filename '%1' were found in '%2'.")
628  .arg(backupFilename).arg(backupDirectory));
629  }
630  else
631  {
632  filename = dir.path() + "/" + dir[0];;
633  if (numfiles > 1)
634  {
635  LOG(VB_FILE, LOG_ERR, LOC +
636  QString("Multiple files beginning with the suggested database "
637  "backup filename '%1' were found in '%2'. "
638  "Assuming the first is the backup.")
639  .arg(backupFilename).arg(backupDirectory));
640  }
641  }
642 
643  if (!filename.isEmpty())
644  {
645  LOG(VB_GENERAL, LOG_CRIT, QString("Backed up database to file: '%1'")
646  .arg(filename));
647  }
648 
649  return true;
650 }
651 
659 {
661  QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
662  QString backupDirectory = GetBackupDirectory();
663 
664  QString command;
665  QString compressCommand("");
666  QString extension = ".sql";
667  if (QFile::exists("/bin/gzip"))
668  compressCommand = "/bin/gzip";
669  else if (QFile::exists("/usr/bin/gzip"))
670  compressCommand = "/usr/bin/gzip";
671  else
672  LOG(VB_GENERAL, LOG_CRIT, "Neither /bin/gzip nor /usr/bin/gzip exist. "
673  "The database backup will be uncompressed.");
674 
675  QString backupFilename = CreateBackupFilename(
676  dbParams.m_dbName + "-" + dbSchemaVer, extension);
677  QString backupPathname = backupDirectory + "/" + backupFilename;
678 
679  QString privateinfo = QString(
680  "[client]\npassword=%1\n[mysqldump]\npassword=%2\n")
681  .arg(dbParams.m_dbPassword).arg(dbParams.m_dbPassword);
682  QString tempExtraConfFile;
683  if (!CreateTemporaryDBConf(privateinfo, tempExtraConfFile))
684  return false;
685 
686  QString portArg = "";
687  if (dbParams.m_dbPort > 0)
688  portArg = QString(" --port='%1'").arg(dbParams.m_dbPort);
689  command = QString("mysqldump --defaults-extra-file='%1' --host='%2'%3"
690  " --user='%4' --add-drop-table --add-locks"
691  " --allow-keywords --complete-insert"
692  " --extended-insert --lock-tables --no-create-db --quick"
693  " '%5' > '%6' 2>/dev/null")
694  .arg(tempExtraConfFile).arg(dbParams.m_dbHostName)
695  .arg(portArg).arg(dbParams.m_dbUserName)
696  .arg(dbParams.m_dbName).arg(backupPathname);
697 
698  LOG(VB_FILE, LOG_INFO, QString("Backing up database with command: '%1'")
699  .arg(command));
700  LOG(VB_GENERAL, LOG_CRIT, QString("Backing up database to file: '%1'")
701  .arg(backupPathname));
702 
704 
705  QByteArray tmpfile = tempExtraConfFile.toLocal8Bit();
706  unlink(tmpfile.constData());
707 
708  if (status != GENERIC_EXIT_OK)
709  {
710  LOG(VB_GENERAL, LOG_ERR, LOC +
711  QString("Error backing up database: '%1' (%2)")
712  .arg(command).arg(status));
713  filename = "__FAILED__";
714  return false;
715  }
716 
717  if (compressCommand != "")
718  {
719  LOG(VB_GENERAL, LOG_CRIT, "Compressing database backup file.");
720  compressCommand += " " + backupPathname;
721  status = myth_system(compressCommand, kMSDontBlockInputDevs);
722 
723  if (status != GENERIC_EXIT_OK)
724  {
725  LOG(VB_GENERAL, LOG_CRIT,
726  "Compression failed, backup file will remain uncompressed.");
727  }
728  else
729  {
730  backupPathname += ".gz";
731 
732  LOG(VB_GENERAL, LOG_CRIT, QString("Database Backup filename: '%1'")
733  .arg(backupPathname));
734  }
735  }
736 
737  LOG(VB_GENERAL, LOG_CRIT, "Database Backup complete.");
738 
739  filename = backupPathname;
740  return true;
741 }
742 
748 {
749  // Allow users to override the string provided by the database server in
750  // case the value was changed to an unrecognizable string by whomever
751  // compiled the MySQL server
752  QString dbmsVersion = gCoreContext->GetSetting("DBMSVersionOverride");
753 
754  if (dbmsVersion.isEmpty())
755  {
757  query.prepare("SELECT VERSION();");
758  if (!query.exec() || !query.next())
759  {
760  LOG(VB_GENERAL, LOG_ERR, LOC +
761  "Unable to determine MySQL version.");
762  MythDB::DBError("DBUtil Querying DBMS version", query);
763  dbmsVersion.clear();
764  }
765  else
766  dbmsVersion = query.value(0).toString();
767  }
768  m_versionString = dbmsVersion;
769 
770  return !m_versionString.isEmpty();
771 }
772 
777 {
778  if (m_versionString.isEmpty())
779  if (!QueryDBMSVersion())
780  return false;
781 
782  static const QRegularExpression parseVersion
783  { R"(^(\d+)(?:\.(\d+)(?:\.(\d+))?)?)" };
784  auto match = parseVersion.match(m_versionString);
785  if (!match.hasMatch())
786  return false;
787 
788  // If any of these wasn't matched, the captured string will be
789  // empty and toInt will parse it as a zero.
790  m_versionMajor = match.capturedRef(1).toInt(nullptr);
791  m_versionMinor = match.capturedRef(2).toInt(nullptr);
792  m_versionPoint = match.capturedRef(3).toInt(nullptr);
793 
794  return m_versionMajor > -1;
795 }
796 
801 {
802  int count = 0;
803 
805  if (!query.isConnected())
806  {
807  LOG(VB_GENERAL, LOG_DEBUG, "Not connected to DB");
808  return count;
809  }
810 
811  if (!query.exec("SHOW PROCESSLIST;"))
812  {
813  MythDB::DBError("DBUtil CountClients", query);
814  return count;
815  }
816 
817  QSqlRecord record = query.record();
818  int db_index = record.indexOf("db");
819  QString dbName = gCoreContext->GetDatabaseParams().m_dbName;
820  QString inUseDB;
821 
822  while (query.next())
823  {
824  inUseDB = query.value(db_index).toString();
825  if (inUseDB == dbName)
826  ++count;
827  }
828 
829  // On average, each myth program has 4 database connections,
830  // but we round up just in case a new program is loading:
831  count = (count + 3)/4;
832 
833  LOG(VB_GENERAL, LOG_DEBUG,
834  QString("DBUtil::CountClients() found %1").arg(count));
835 
836  return count;
837 }
838 
843 {
844  query.prepare("SELECT GET_LOCK('schemaLock', :TIMEOUT)");
845  query.bindValue(":TIMEOUT", timeout_secs);
846  return query.exec() && query.first() && query.value(0).toBool();
847 }
848 
850 {
851  query.prepare("SELECT RELEASE_LOCK('schemaLock')");
852  if (!query.exec())
853  {
854  MythDB::DBError("DBUtil UnlockSchema", query);
855  }
856 }
857 
862 {
864  query.prepare("SELECT CONVERT_TZ(NOW(), 'SYSTEM', 'Etc/UTC')");
865  if (!query.exec() || !query.next())
866  {
867  LOG(VB_GENERAL, LOG_ERR, "MySQL time zone support check failed");
868  return false;
869  }
870 
871  return !query.value(0).isNull();
872 }
873 
874 /* vim: set expandtab tabstop=4 shiftwidth=4: */
DBUtil::QueryDBMSVersion
bool QueryDBMSVersion(void)
Reads and returns the QString version name from the DBMS or returns QString() in the event of an erro...
Definition: dbutil.cpp:747
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:124
LOC
#define LOC
Definition: dbutil.cpp:26
MythDate::toString
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
Definition: mythdate.cpp:80
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:72
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
DatabaseParams::m_dbHostName
QString m_dbHostName
database server
Definition: mythdbparams.h:22
dbutil.h
kMSDontBlockInputDevs
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
Definition: mythsystem.h:35
kMSAnonLog
@ kMSAnonLog
anonymize the logs
Definition: mythsystem.h:43
mythdb.h
DatabaseParams
Structure containing the basic Database parameters.
Definition: mythdbparams.h:10
MSqlQuery::record
QSqlRecord record(void) const
Definition: mythdbcon.h:204
DBUtil::CreateBackupFilename
static QString CreateBackupFilename(const QString &prefix="mythconverg", const QString &extension=".sql")
Creates a filename to use for the filename.
Definition: dbutil.cpp:466
DBUtil::IsBackupInProgress
static bool IsBackupInProgress(void)
Test to see if a DB backup is in progress.
Definition: dbutil.cpp:88
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:197
arg
arg(title).arg(filename).arg(doDelete))
kDB_Backup_Empty_DB
@ kDB_Backup_Empty_DB
Definition: dbutil.h:14
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DBUtil::CheckTables
static bool CheckTables(bool repair=false, const QString &options="QUICK")
Checks database tables.
Definition: dbutil.cpp:274
MythCoreContext::GetDatabaseParams
DatabaseParams GetDatabaseParams(void)
Definition: mythcorecontext.h:148
mythdirs.h
myth_system
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
Definition: mythsystemlegacy.cpp:502
hardwareprofile.distros.mythtv_data.data_mythtv.prefix
string prefix
Definition: data_mythtv.py:40
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
mythburn.FILE
int FILE
Definition: mythburn.py:139
DBUtil::ParseDBMSVersion
bool ParseDBMSVersion(void)
Parses m_versionString to find the major, minor, and point version.
Definition: dbutil.cpp:776
mythsystemlegacy.h
DBUtil::m_versionMinor
int m_versionMinor
Definition: dbutil.h:81
DBUtil::GetDBMSVersion
QString GetDBMSVersion(void)
Returns the QString version name of the DBMS or QString() in the event of an error.
Definition: dbutil.cpp:34
DBUtil::m_versionString
QString m_versionString
Definition: dbutil.h:78
DatabaseParams::m_dbPort
int m_dbPort
database port
Definition: mythdbparams.h:24
mythdate.h
minor
#define minor(X)
Definition: compat.h:138
kDB_Backup_Disabled
@ kDB_Backup_Disabled
Definition: dbutil.h:15
mythlogging.h
DBUtil::CheckRepairStatus
static QStringList CheckRepairStatus(MSqlQuery &query)
Parse the results of a CHECK TABLE or REPAIR TABLE run.
Definition: dbutil.cpp:379
DBUtil::CreateTemporaryDBConf
static bool CreateTemporaryDBConf(const QString &privateinfo, QString &filename)
Creates temporary file containing sensitive DB info.
Definition: dbutil.cpp:518
MythDate::kFilename
@ kFilename
Default UTC, "yyyyMMddhhmmss".
Definition: mythdate.h:18
MSqlQuery::first
bool first(void)
Wrap QSqlQuery::first() so we can display the query results.
Definition: mythdbcon.cpp:793
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:178
GetShareDir
QString GetShareDir(void)
Definition: mythdirs.cpp:222
kDB_Backup_Completed
@ kDB_Backup_Completed
Definition: dbutil.h:13
createTempFile
QString createTempFile(QString name_template, bool dir)
Definition: mythmiscutil.cpp:371
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
DBUtil::BackupDB
static MythDBBackupStatus BackupDB(QString &filename, bool disableRotation=false)
Requests a backup of the database.
Definition: dbutil.cpp:186
DBUtil::CheckTimeZoneSupport
static bool CheckTimeZoneSupport(void)
Check if MySQL has working timz zone support.
Definition: dbutil.cpp:861
storagegroup.h
DBUtil::CountClients
static int CountClients(void)
Estimate the number of MythTV programs using the database.
Definition: dbutil.cpp:800
DBUtil::m_versionPoint
int m_versionPoint
Definition: dbutil.h:82
DBUtil::DoBackup
static bool DoBackup(const QString &backupScript, QString &filename, bool disableRotation=false)
Creates a backup of the database by executing the backupScript.
Definition: dbutil.cpp:562
DatabaseParams::m_dbPassword
QString m_dbPassword
DB password.
Definition: mythdbparams.h:26
kDB_Backup_Failed
@ kDB_Backup_Failed
Definition: dbutil.h:12
DatabaseParams::m_dbName
QString m_dbName
database name
Definition: mythdbparams.h:27
StorageGroup::GetDirList
QStringList GetDirList(void) const
Definition: storagegroup.h:23
MSqlQuery::isConnected
bool isConnected(void) const
Only updated once during object creation.
Definition: mythdbcon.h:134
uint
unsigned int uint
Definition: compat.h:140
MythDBBackupStatus
MythDBBackupStatus
Definition: dbutil.h:9
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
DBUtil::TryLockSchema
static bool TryLockSchema(MSqlQuery &query, uint timeout_secs)
Try to get a lock on the table schemalock.
Definition: dbutil.cpp:842
DBUtil::RepairTables
static bool RepairTables(const QStringList &tables)
Repairs database tables.
Definition: dbutil.cpp:332
MythDate::fromString
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:30
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:926
mythmiscutil.h
MythDate::secsInPast
std::chrono::seconds secsInPast(const QDateTime &past)
Definition: mythdate.cpp:199
mythcorecontext.h
StorageGroup::FindNextDirMostFree
QString FindNextDirMostFree(void)
Definition: storagegroup.cpp:671
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1174
DBUtil::GetBackupDirectory
static QString GetBackupDirectory()
Determines the appropriate path for the database backup.
Definition: dbutil.cpp:481
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
DatabaseParams::m_dbUserName
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:25
DBUtil::kUnknownVersionNumber
static const int kUnknownVersionNumber
Definition: dbutil.h:57
dirList
QStringList dirList
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1172
DBUtil::m_versionMajor
int m_versionMajor
Definition: dbutil.h:80
DBUtil::IsNewDatabase
static bool IsNewDatabase(void)
Returns true for a new (empty) database.
Definition: dbutil.cpp:74
StorageGroup
Definition: storagegroup.h:11
MythDate::kDatabase
@ kDatabase
Default UTC, database format.
Definition: mythdate.h:27
DBUtil::UnlockSchema
static void UnlockSchema(MSqlQuery &query)
Definition: dbutil.cpp:849
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:858
exitcodes.h
DBUtil::GetTables
static QStringList GetTables(const QStringList &engines=QStringList())
Retrieves a list of tables from the database.
Definition: dbutil.cpp:423
query
MSqlQuery query(MSqlQuery::InitCon())
nv_python_libs.bbciplayer.bbciplayer_api.version
string version
Definition: bbciplayer_api.py:81
build_compdb.options
options
Definition: build_compdb.py:11
MythCoreContext::SaveSettingOnHost
bool SaveSettingOnHost(const QString &key, const QString &newValue, const QString &host)
Definition: mythcorecontext.cpp:911
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:918
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
DBUtil::CompareDBMSVersion
int CompareDBMSVersion(int major, int minor=0, int point=0)
Compares the version of the active DBMS with the provided version.
Definition: dbutil.cpp:53