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 #if QT_VERSION < QT_VERSION_CHECK(5,15,2)
29 #define capturedView capturedRef
30 #endif
31 
32 const int DBUtil::kUnknownVersionNumber = INT_MIN;
33 
39 {
40  if (m_versionString.isEmpty())
42  return m_versionString;
43 }
44 
57 int DBUtil::CompareDBMSVersion(int major, int minor, int point)
58 {
59  if (m_versionMajor < 0)
60  if (!ParseDBMSVersion())
61  return kUnknownVersionNumber;
62 
63  int result = 0;
65  std::array<int,3> compareto {major, minor, point};
66  for (int i = 0; i < 3 && !result; i++)
67  {
68  if ((version[i] > -1) || (compareto[i] != 0))
69  result = version[i] - compareto[i];
70  }
71 
72  return result;
73 }
74 
79 {
80  const QStringList tables = GetTables();
81  const int size = tables.size();
82  // Usually there will be a single table called schemalock, but check for
83  // no tables, also, just in case.
84  return (((size == 1) && (tables.at(0).endsWith(".`schemalock`"))) ||
85  (size == 0));
86 }
87 
93 {
94  QString backupStartTimeStr =
95  gCoreContext->GetSetting("BackupDBLastRunStart");
96  QString backupEndTimeStr = gCoreContext->GetSetting("BackupDBLastRunEnd");
97 
98  if (backupStartTimeStr.isEmpty())
99  {
100  LOG(VB_DATABASE, LOG_ERR, "DBUtil::BackupInProgress(): No start time "
101  "found, database backup is not in progress.");
102  return false;
103  }
104 
105  backupStartTimeStr.replace(" ", "T");
106 
107  QDateTime backupStartTime = MythDate::fromString(backupStartTimeStr);
108  auto backupElapsed = MythDate::secsInPast(backupStartTime);
109 
110  // No end time set
111  if (backupEndTimeStr.isEmpty())
112  {
113  // If DB Backup started less then 10 minutes ago, assume still running
114  if (backupElapsed < 10min)
115  {
116  LOG(VB_DATABASE, LOG_INFO,
117  QString("DBUtil::BackupInProgress(): Found "
118  "database backup start time of %1 which was %2 seconds "
119  "ago, therefore it appears the backup is still running.")
120  .arg(backupStartTimeStr)
121  .arg(backupElapsed.count()));
122  return true;
123  }
124  LOG(VB_DATABASE, LOG_ERR, QString("DBUtil::BackupInProgress(): "
125  "Database backup started at %1, but no end time was found. "
126  "The backup started %2 seconds ago and should have "
127  "finished by now therefore it appears it is not running .")
128  .arg(backupStartTimeStr)
129  .arg(backupElapsed.count()));
130  return false;
131  }
132 
133  backupEndTimeStr.replace(" ", "T");
134 
135  QDateTime backupEndTime = MythDate::fromString(backupEndTimeStr);
136 
137  if (backupEndTime >= backupStartTime)
138  {
139  LOG(VB_DATABASE, LOG_ERR,
140  QString("DBUtil::BackupInProgress(): Found "
141  "database backup end time of %1 later than start time "
142  "of %2, therefore backup is not running.")
143  .arg(backupEndTimeStr, backupStartTimeStr));
144  return false;
145  }
146  if (backupElapsed > 10min)
147  {
148  LOG(VB_DATABASE, LOG_ERR,
149  QString("DBUtil::BackupInProgress(): "
150  "Database backup started at %1, but has not ended yet. "
151  "The backup started %2 seconds ago and should have "
152  "finished by now therefore it appears it is not running")
153  .arg(backupStartTimeStr)
154  .arg(backupElapsed.count()));
155  return false;
156  }
157 
158  // start > end and started less than 10 minutes ago
159  LOG(VB_DATABASE, LOG_INFO, QString("DBUtil::BackupInProgress(): "
160  "Database backup started at %1, and is still running.")
161  .arg(backupStartTimeStr));
162  return true;
163 }
164 
190 MythDBBackupStatus DBUtil::BackupDB(QString &filename, bool disableRotation)
191 {
192  filename = QString();
193 
194 #ifdef _WIN32
195  LOG(VB_GENERAL, LOG_CRIT, "Database backups disabled on Windows.");
196  return kDB_Backup_Disabled;
197 #else
198 
199  if (gCoreContext->GetBoolSetting("DisableAutomaticBackup", false))
200  {
201  LOG(VB_GENERAL, LOG_CRIT,
202  "Database backups disabled. Skipping backup.");
203  return kDB_Backup_Disabled;
204  }
205 
206  if (IsNewDatabase())
207  {
208  LOG(VB_GENERAL, LOG_CRIT, "New database detected. Skipping backup.");
209  return kDB_Backup_Empty_DB;
210  }
211 
212  QString backupScript = GetShareDir() + "mythconverg_backup.pl";
213  backupScript = gCoreContext->GetSetting("DatabaseBackupScript",
214  backupScript);
215 
216  if (!QFile::exists(backupScript))
217  {
218  LOG(VB_GENERAL, LOG_CRIT, QString("Database backup script does "
219  "not exist: %1").arg(backupScript));
220  backupScript.clear();
221  }
222 
223  bool result = false;
224  MSqlQuery query(MSqlQuery::InitCon());
225 
227  "BackupDBLastRunStart",
229 
230  if (!backupScript.isEmpty())
231  {
232  result = DoBackup(backupScript, filename, disableRotation);
233  if (!result)
234  LOG(VB_GENERAL, LOG_CRIT, "Script-based database backup failed. "
235  "Retrying with internal backup.");
236  }
237 
238  if (!result)
239  result = DoBackup(filename);
240 
242  "BackupDBLastRunEnd",
244 
245  if (query.isConnected())
246  {
247  QString dbTag("BackupDB");
248  query.prepare("DELETE FROM housekeeping WHERE tag = :TAG ;");
249  query.bindValue(":TAG", dbTag);
250  if (!query.exec())
251  MythDB::DBError("DBUtil::BackupDB", query);
252 
253  query.prepare("INSERT INTO housekeeping(tag,lastrun) "
254  "values(:TAG ,now()) ;");
255  query.bindValue(":TAG", dbTag);
256  if (!query.exec())
257  MythDB::DBError("DBUtil::BackupDB", query);
258  }
259 
260  if (result)
261  return kDB_Backup_Completed;
262 
263  return kDB_Backup_Failed;
264 #endif // _WIN32
265 }
266 
278 bool DBUtil::CheckTables(const bool repair, const QString &options)
279 {
280  MSqlQuery query(MSqlQuery::InitCon());
281  if (!query.isConnected())
282  return false;
283 
284  const QStringList all_tables = GetTables(QStringList("MyISAM"));
285 
286  if (all_tables.empty())
287  return true;
288 
289  QString sql = QString("CHECK TABLE %1 %2;")
290  .arg(all_tables.join(", "), options);
291 
292  LOG(VB_GENERAL, LOG_CRIT, "Checking database tables.");
293  if (!query.exec(sql))
294  {
295  MythDB::DBError("DBUtil Checking Tables", query);
296  return false;
297  }
298 
299  QStringList tables = CheckRepairStatus(query);
300  bool result = true;
301  if (!tables.empty())
302  {
303  LOG(VB_GENERAL, LOG_CRIT, QString("Found crashed database table(s): %1")
304  .arg(tables.join(", ")));
305  if (repair)
306  {
307  // If RepairTables() repairs the crashed tables, return true
308  result = RepairTables(tables);
309  }
310  else
311  {
312  result = false;
313  }
314  }
315 
316  return result;
317 }
318 
336 bool DBUtil::RepairTables(const QStringList &tables)
337 {
338  MSqlQuery query(MSqlQuery::InitCon());
339  if (!query.isConnected())
340  return false;
341 
342  QString all_tables = tables.join(", ");
343  LOG(VB_GENERAL, LOG_CRIT, QString("Repairing database tables: %1")
344  .arg(all_tables));
345 
346  QString sql = QString("REPAIR TABLE %1;").arg(all_tables);
347  if (!query.exec(sql))
348  {
349  MythDB::DBError("DBUtil Repairing Tables", query);
350  return false;
351  }
352 
353  QStringList bad_tables = CheckRepairStatus(query);
354  bool result = true;
355  if (!bad_tables.empty())
356  {
357  LOG(VB_GENERAL, LOG_CRIT,
358  QString("Unable to repair crashed table(s): %1")
359  .arg(bad_tables.join(", ")));
360  result = false;
361  }
362  return result;
363 }
364 
384 {
385  QStringList tables;
386  QSqlRecord record = query.record();
387  int table_index = record.indexOf("Table");
388  int type_index = record.indexOf("Msg_type");
389  int text_index = record.indexOf("Msg_text");
390  QString table;
391  QString type;
392  QString text;
393  QString previous_table;
394  bool ok = true;
395  while (query.next())
396  {
397  table = query.value(table_index).toString();
398  type = query.value(type_index).toString();
399  text = query.value(text_index).toString();
400  if (table != previous_table)
401  {
402  if (!ok)
403  {
404  tables.append(previous_table);
405  ok = true;
406  }
407  previous_table = table;
408  }
409  // If the final row shows status OK, the table is now good
410  if ("status" == type.toLower() && "ok" == text.toLower())
411  ok = true;
412  else if ("error" == type.toLower() ||
413  ("status" == type.toLower() && "ok" != text.toLower()))
414  ok = false;
415  }
416  // Check the last table in the list
417  if (!ok)
418  tables.append(table);
419  return tables;
420 }
421 
427 QStringList DBUtil::GetTables(const QStringList &engines)
428 {
429  QStringList result;
430 
431  MSqlQuery query(MSqlQuery::InitCon());
432  if (!query.isConnected())
433  return result;
434 
435  QString sql = "SELECT CONCAT('`', TABLE_SCHEMA, "
436  " '`.`', TABLE_NAME, "
437  " '`') AS `TABLE_NAME` "
438  " FROM INFORMATION_SCHEMA.TABLES "
439  " WHERE TABLE_SCHEMA = DATABASE() "
440  " AND TABLE_TYPE = 'BASE TABLE'";
441  if (!engines.empty())
442  sql.append(QString(" AND ENGINE IN ('%1')")
443  .arg(engines.join("', '")));
444  if (!query.exec(sql))
445  {
446  MythDB::DBError("DBUtil Finding Tables", query);
447  return result;
448  }
449 
450  while (query.next())
451  {
452  result.append(query.value(0).toString());
453  }
454 
455  return result;
456 }
457 
470 QString DBUtil::CreateBackupFilename(const QString& prefix, const QString& extension)
471 {
473  return QString("%1-%2%3").arg(prefix, time, extension);
474 }
475 
486 {
487  QString directory;
488  StorageGroup sgroup("DB Backups", gCoreContext->GetHostName());
489  QStringList dirList = sgroup.GetDirList();
490  if (!dirList.empty())
491  {
492  directory = sgroup.FindNextDirMostFree();
493 
494  if (!QDir(directory).exists())
495  {
496  LOG(VB_FILE, LOG_INFO, "GetBackupDirectory() - ignoring " +
497  directory + ", using /tmp");
498  directory.clear();
499  }
500  }
501 
502  if (directory.isNull())
503  {
504  // Rather than use kDefaultStorageDir, the default for
505  // FindNextDirMostFree() when no dirs are defined for the StorageGroup,
506  // use /tmp as it's possible that kDefaultStorageDir doesn't exist
507  // and (at least on *nix) less possible that /tmp doesn't exist
508  directory = "/tmp";
509  }
510 
511  return directory;
512 }
513 
523  const QString &privateinfo, QString &filename)
524 {
525  bool ok = true;
526  filename = createTempFile("/tmp/mythtv_db_backup_conf_XXXXXX");
527  const QByteArray tmpfile = filename.toLocal8Bit();
528 
529  FILE *fp = fopen(tmpfile.constData(), "w");
530  if (!fp)
531  {
532  LOG(VB_GENERAL, LOG_ERR, LOC +
533  QString("Unable to create temporary "
534  "configuration file for creating DB backup: %1")
535  .arg(tmpfile.constData()));
536  filename = "";
537  ok = false;
538  }
539  else
540  {
541  if (chmod(tmpfile.constData(), S_IRUSR))
542  {
543  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error changing permissions '%1'")
544  .arg(tmpfile.constData()) + ENO);
545  }
546 
547  QByteArray outarr = privateinfo.toLocal8Bit();
548  fprintf(fp, "%s", outarr.constData());
549 
550  if (fclose(fp))
551  {
552  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error closing '%1'")
553  .arg(tmpfile.constData()) + ENO);
554  }
555  }
556 
557  return ok;
558 }
559 
566 bool DBUtil::DoBackup(const QString &backupScript, QString &filename,
567  bool disableRotation)
568 {
570  QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
571  QString backupDirectory = GetBackupDirectory();
572  QString backupFilename = CreateBackupFilename(dbParams.m_dbName + "-" +
573  dbSchemaVer, ".sql");
574  QString scriptArgs = gCoreContext->GetSetting("BackupDBScriptArgs");
575  QString rotate = "";
576  if (disableRotation)
577  {
578  if (!(scriptArgs.contains("rotate", Qt::CaseInsensitive)))
579  rotate = "rotate=-1";
580  }
581 
582 
583  QString privateinfo =
584  QString("DBHostName=%1\nDBPort=%2\n"
585  "DBUserName=%3\nDBPassword=%4\n"
586  "DBName=%5\nDBSchemaVer=%6\n"
587  "DBBackupDirectory=%7\nDBBackupFilename=%8\n%9\n")
588  .arg(dbParams.m_dbHostName, QString::number(dbParams.m_dbPort),
589  dbParams.m_dbUserName, dbParams.m_dbPassword,
590  dbParams.m_dbName, dbSchemaVer,
591  backupDirectory, backupFilename,
592  rotate);
593  QString tempDatabaseConfFile;
594  bool hastemp = CreateTemporaryDBConf(privateinfo, tempDatabaseConfFile);
595  if (!hastemp)
596  LOG(VB_GENERAL, LOG_ERR, LOC + "Attempting backup, anyway.");
597 
598  LOG(VB_GENERAL, LOG_ERR, QString("Backing up database with script: '%1'")
599  .arg(backupScript));
600 
601  QString command = backupScript + " " + scriptArgs + " " +
602  tempDatabaseConfFile;
604 
605  if (hastemp)
606  {
607  QByteArray tmpfile = tempDatabaseConfFile.toLocal8Bit();
608  unlink(tmpfile.constData());
609  }
610 
611  if (status != GENERIC_EXIT_OK)
612  {
613  LOG(VB_GENERAL, LOG_ERR, LOC +
614  QString("Error backing up database: %1 (%2)")
615  .arg(command).arg(status));
616  filename = "__FAILED__";
617  return false;
618  }
619 
620  LOG(VB_GENERAL, LOG_CRIT, "Database Backup complete.");
621 
622  QDir dir(backupDirectory, backupFilename + "*");
623  uint numfiles = dir.count();
624  if (numfiles < 1)
625  {
626  // If no file begins with the suggested filename, don't show the backup
627  // filename in the GUI message -- the script probably used some other
628  // filename
629  filename = "";
630  LOG(VB_FILE, LOG_ERR, LOC +
631  QString("No files beginning with the suggested database backup "
632  "filename '%1' were found in '%2'.")
633  .arg(backupFilename, backupDirectory));
634  }
635  else
636  {
637  filename = dir.path() + "/" + dir[0];;
638  if (numfiles > 1)
639  {
640  LOG(VB_FILE, LOG_ERR, LOC +
641  QString("Multiple files beginning with the suggested database "
642  "backup filename '%1' were found in '%2'. "
643  "Assuming the first is the backup.")
644  .arg(backupFilename, backupDirectory));
645  }
646  }
647 
648  if (!filename.isEmpty())
649  {
650  LOG(VB_GENERAL, LOG_CRIT, QString("Backed up database to file: '%1'")
651  .arg(filename));
652  }
653 
654  return true;
655 }
656 
664 {
666  QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
667  QString backupDirectory = GetBackupDirectory();
668 
669  QString command;
670  QString compressCommand("");
671  QString extension = ".sql";
672  if (QFile::exists("/bin/gzip"))
673  compressCommand = "/bin/gzip";
674  else if (QFile::exists("/usr/bin/gzip"))
675  compressCommand = "/usr/bin/gzip";
676  else
677  LOG(VB_GENERAL, LOG_CRIT, "Neither /bin/gzip nor /usr/bin/gzip exist. "
678  "The database backup will be uncompressed.");
679 
680  QString backupFilename = CreateBackupFilename(
681  dbParams.m_dbName + "-" + dbSchemaVer, extension);
682  QString backupPathname = backupDirectory + "/" + backupFilename;
683 
684  QString privateinfo = QString(
685  "[client]\npassword=%1\n[mysqldump]\npassword=%2\n")
686  .arg(dbParams.m_dbPassword, dbParams.m_dbPassword);
687  QString tempExtraConfFile;
688  if (!CreateTemporaryDBConf(privateinfo, tempExtraConfFile))
689  return false;
690 
691  QString portArg = "";
692  if (dbParams.m_dbPort > 0)
693  portArg = QString(" --port='%1'").arg(dbParams.m_dbPort);
694  command = QString("mysqldump --defaults-extra-file='%1' --host='%2'%3"
695  " --user='%4' --add-drop-table --add-locks"
696  " --allow-keywords --complete-insert"
697  " --extended-insert --lock-tables --no-create-db --quick"
698  " '%5' > '%6' 2>/dev/null")
699  .arg(tempExtraConfFile, dbParams.m_dbHostName,
700  portArg, dbParams.m_dbUserName,
701  dbParams.m_dbName, backupPathname);
702 
703  LOG(VB_FILE, LOG_INFO, QString("Backing up database with command: '%1'")
704  .arg(command));
705  LOG(VB_GENERAL, LOG_CRIT, QString("Backing up database to file: '%1'")
706  .arg(backupPathname));
707 
709 
710  QByteArray tmpfile = tempExtraConfFile.toLocal8Bit();
711  unlink(tmpfile.constData());
712 
713  if (status != GENERIC_EXIT_OK)
714  {
715  LOG(VB_GENERAL, LOG_ERR, LOC +
716  QString("Error backing up database: '%1' (%2)")
717  .arg(command).arg(status));
718  filename = "__FAILED__";
719  return false;
720  }
721 
722  if (compressCommand != "")
723  {
724  LOG(VB_GENERAL, LOG_CRIT, "Compressing database backup file.");
725  compressCommand += " " + backupPathname;
726  status = myth_system(compressCommand, kMSDontBlockInputDevs);
727 
728  if (status != GENERIC_EXIT_OK)
729  {
730  LOG(VB_GENERAL, LOG_CRIT,
731  "Compression failed, backup file will remain uncompressed.");
732  }
733  else
734  {
735  backupPathname += ".gz";
736 
737  LOG(VB_GENERAL, LOG_CRIT, QString("Database Backup filename: '%1'")
738  .arg(backupPathname));
739  }
740  }
741 
742  LOG(VB_GENERAL, LOG_CRIT, "Database Backup complete.");
743 
744  filename = backupPathname;
745  return true;
746 }
747 
753 {
754  // Allow users to override the string provided by the database server in
755  // case the value was changed to an unrecognizable string by whomever
756  // compiled the MySQL server
757  QString dbmsVersion = gCoreContext->GetSetting("DBMSVersionOverride");
758 
759  if (dbmsVersion.isEmpty())
760  {
761  MSqlQuery query(MSqlQuery::InitCon());
762  query.prepare("SELECT VERSION();");
763  if (!query.exec() || !query.next())
764  {
765  LOG(VB_GENERAL, LOG_ERR, LOC +
766  "Unable to determine MySQL version.");
767  MythDB::DBError("DBUtil Querying DBMS version", query);
768  dbmsVersion.clear();
769  }
770  else
771  dbmsVersion = query.value(0).toString();
772  }
773  m_versionString = dbmsVersion;
774 
775  return !m_versionString.isEmpty();
776 }
777 
782 {
783  if (m_versionString.isEmpty())
784  if (!QueryDBMSVersion())
785  return false;
786 
787  static const QRegularExpression parseVersion
788  { R"(^(\d+)(?:\.(\d+)(?:\.(\d+))?)?)" };
789  auto match = parseVersion.match(m_versionString);
790  if (!match.hasMatch())
791  return false;
792 
793  // If any of these wasn't matched, the captured string will be
794  // empty and toInt will parse it as a zero.
795  m_versionMajor = match.capturedView(1).toInt(nullptr);
796  m_versionMinor = match.capturedView(2).toInt(nullptr);
797  m_versionPoint = match.capturedView(3).toInt(nullptr);
798 
799  return m_versionMajor > -1;
800 }
801 
806 {
807  int count = 0;
808 
809  MSqlQuery query(MSqlQuery::InitCon());
810  if (!query.isConnected())
811  {
812  LOG(VB_GENERAL, LOG_DEBUG, "Not connected to DB");
813  return count;
814  }
815 
816  if (!query.exec("SHOW PROCESSLIST;"))
817  {
818  MythDB::DBError("DBUtil CountClients", query);
819  return count;
820  }
821 
822  QSqlRecord record = query.record();
823  int db_index = record.indexOf("db");
824  QString dbName = gCoreContext->GetDatabaseParams().m_dbName;
825  QString inUseDB;
826 
827  while (query.next())
828  {
829  inUseDB = query.value(db_index).toString();
830  if (inUseDB == dbName)
831  ++count;
832  }
833 
834  // On average, each myth program has 4 database connections,
835  // but we round up just in case a new program is loading:
836  count = (count + 3)/4;
837 
838  LOG(VB_GENERAL, LOG_DEBUG,
839  QString("DBUtil::CountClients() found %1").arg(count));
840 
841  return count;
842 }
843 
847 bool DBUtil::TryLockSchema(MSqlQuery &query, uint timeout_secs)
848 {
849  query.prepare("SELECT GET_LOCK('schemaLock', :TIMEOUT)");
850  query.bindValue(":TIMEOUT", timeout_secs);
851  return query.exec() && query.first() && query.value(0).toBool();
852 }
853 
855 {
856  query.prepare("SELECT RELEASE_LOCK('schemaLock')");
857  if (!query.exec())
858  {
859  MythDB::DBError("DBUtil UnlockSchema", query);
860  }
861 }
862 
867 {
868  MSqlQuery query(MSqlQuery::InitCon());
869  query.prepare("SELECT CONVERT_TZ(NOW(), 'SYSTEM', 'Etc/UTC')");
870  if (!query.exec() || !query.next())
871  {
872  LOG(VB_GENERAL, LOG_ERR, "MySQL time zone support check failed");
873  return false;
874  }
875 
876  return !query.value(0).isNull();
877 }
878 
879 /* 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:752
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
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:36
kMSAnonLog
@ kMSAnonLog
anonymize the logs
Definition: mythsystem.h:44
mythdb.h
DatabaseParams
Structure containing the basic Database parameters.
Definition: mythdbparams.h:10
MSqlQuery::record
QSqlRecord record(void) const
Definition: mythdbcon.h:209
DBUtil::CreateBackupFilename
static QString CreateBackupFilename(const QString &prefix="mythconverg", const QString &extension=".sql")
Creates a filename to use for the filename.
Definition: dbutil.cpp:470
DBUtil::IsBackupInProgress
static bool IsBackupInProgress(void)
Test to see if a DB backup is in progress.
Definition: dbutil.cpp:92
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:197
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:278
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:781
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:38
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:383
DBUtil::CreateTemporaryDBConf
static bool CreateTemporaryDBConf(const QString &privateinfo, QString &filename)
Creates temporary file containing sensitive DB info.
Definition: dbutil.cpp:522
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:822
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:200
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
DBUtil::BackupDB
static MythDBBackupStatus BackupDB(QString &filename, bool disableRotation=false)
Requests a backup of the database.
Definition: dbutil.cpp:190
DBUtil::CheckTimeZoneSupport
static bool CheckTimeZoneSupport(void)
Check if MySQL has working timz zone support.
Definition: dbutil.cpp:866
storagegroup.h
DBUtil::CountClients
static int CountClients(void)
Estimate the number of MythTV programs using the database.
Definition: dbutil.cpp:805
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:566
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:847
DBUtil::RepairTables
static bool RepairTables(const QStringList &tables)
Repairs database tables.
Definition: dbutil.cpp:336
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:930
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
DBUtil::GetBackupDirectory
static QString GetBackupDirectory()
Determines the appropriate path for the database backup.
Definition: dbutil.cpp:485
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:893
DatabaseParams::m_dbUserName
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:25
DBUtil::kUnknownVersionNumber
static const int kUnknownVersionNumber
Definition: dbutil.h:57
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:78
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:854
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:862
exitcodes.h
DBUtil::GetTables
static QStringList GetTables(const QStringList &engines=QStringList())
Retrieves a list of tables from the database.
Definition: dbutil.cpp:427
build_compdb.filename
filename
Definition: build_compdb.py:21
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:915
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:922
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
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:57