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 <QRegExp>
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 
105  // No end time set
106  if (backupEndTimeStr.isEmpty())
107  {
108  // If DB Backup started less then 10 minutes ago, assume still running
109  if (backupStartTime.secsTo(MythDate::current()) < 600)
110  {
111  LOG(VB_DATABASE, LOG_INFO,
112  QString("DBUtil::BackupInProgress(): Found "
113  "database backup start time of %1 which was %2 seconds "
114  "ago, therefore it appears the backup is still running.")
115  .arg(backupStartTimeStr)
116  .arg(backupStartTime.secsTo(MythDate::current())));
117  return true;
118  }
119  LOG(VB_DATABASE, LOG_ERR, QString("DBUtil::BackupInProgress(): "
120  "Database backup started at %1, but no end time was found. "
121  "The backup started %2 seconds ago and should have "
122  "finished by now therefore it appears it is not running .")
123  .arg(backupStartTimeStr)
124  .arg(backupStartTime.secsTo(MythDate::current())));
125  return false;
126  }
127 
128  backupEndTimeStr.replace(" ", "T");
129 
130  QDateTime backupEndTime = MythDate::fromString(backupEndTimeStr);
131 
132  if (backupEndTime >= backupStartTime)
133  {
134  LOG(VB_DATABASE, LOG_ERR,
135  QString("DBUtil::BackupInProgress(): Found "
136  "database backup end time of %1 later than start time "
137  "of %2, therefore backup is not running.")
138  .arg(backupEndTimeStr).arg(backupStartTimeStr));
139  return false;
140  }
141  if (backupStartTime.secsTo(MythDate::current()) > 600)
142  {
143  LOG(VB_DATABASE, LOG_ERR,
144  QString("DBUtil::BackupInProgress(): "
145  "Database backup started at %1, but has not ended yet. "
146  "The backup started %2 seconds ago and should have "
147  "finished by now therefore it appears it is not running")
148  .arg(backupStartTimeStr)
149  .arg(backupStartTime.secsTo(MythDate::current())));
150  return false;
151  }
152 
153  // start > end and started less than 10 minutes ago
154  LOG(VB_DATABASE, LOG_INFO, QString("DBUtil::BackupInProgress(): "
155  "Database backup started at %1, and is still running.")
156  .arg(backupStartTimeStr));
157  return true;
158 }
159 
185 MythDBBackupStatus DBUtil::BackupDB(QString &filename, bool disableRotation)
186 {
187  filename = QString();
188 
189 #ifdef _WIN32
190  LOG(VB_GENERAL, LOG_CRIT, "Database backups disabled on Windows.");
191  return kDB_Backup_Disabled;
192 #else
193 
194  if (gCoreContext->GetBoolSetting("DisableAutomaticBackup", false))
195  {
196  LOG(VB_GENERAL, LOG_CRIT,
197  "Database backups disabled. Skipping backup.");
198  return kDB_Backup_Disabled;
199  }
200 
201  if (IsNewDatabase())
202  {
203  LOG(VB_GENERAL, LOG_CRIT, "New database detected. Skipping backup.");
204  return kDB_Backup_Empty_DB;
205  }
206 
207  QString backupScript = GetShareDir() + "mythconverg_backup.pl";
208  backupScript = gCoreContext->GetSetting("DatabaseBackupScript",
209  backupScript);
210 
211  if (!QFile::exists(backupScript))
212  {
213  LOG(VB_GENERAL, LOG_CRIT, QString("Database backup script does "
214  "not exist: %1").arg(backupScript));
215  backupScript.clear();
216  }
217 
218  bool result = false;
220 
222  "BackupDBLastRunStart",
224 
225  if (!backupScript.isEmpty())
226  {
227  result = DoBackup(backupScript, filename, disableRotation);
228  if (!result)
229  LOG(VB_GENERAL, LOG_CRIT, "Script-based database backup failed. "
230  "Retrying with internal backup.");
231  }
232 
233  if (!result)
234  result = DoBackup(filename);
235 
237  "BackupDBLastRunEnd",
239 
240  if (query.isConnected())
241  {
242  QString dbTag("BackupDB");
243  query.prepare("DELETE FROM housekeeping WHERE tag = :TAG ;");
244  query.bindValue(":TAG", dbTag);
245  if (!query.exec())
246  MythDB::DBError("DBUtil::BackupDB", query);
247 
248  query.prepare("INSERT INTO housekeeping(tag,lastrun) "
249  "values(:TAG ,now()) ;");
250  query.bindValue(":TAG", dbTag);
251  if (!query.exec())
252  MythDB::DBError("DBUtil::BackupDB", query);
253  }
254 
255  if (result)
256  return kDB_Backup_Completed;
257 
258  return kDB_Backup_Failed;
259 #endif // _WIN32
260 }
261 
273 bool DBUtil::CheckTables(const bool repair, const QString &options)
274 {
276  if (!query.isConnected())
277  return false;
278 
279  const QStringList all_tables = GetTables(QStringList("MyISAM"));
280 
281  if (all_tables.empty())
282  return true;
283 
284  QString sql = QString("CHECK TABLE %1 %2;").arg(all_tables.join(", "))
285  .arg(options);
286 
287  LOG(VB_GENERAL, LOG_CRIT, "Checking database tables.");
288  if (!query.exec(sql))
289  {
290  MythDB::DBError("DBUtil Checking Tables", query);
291  return false;
292  }
293 
294  QStringList tables = CheckRepairStatus(query);
295  bool result = true;
296  if (!tables.empty())
297  {
298  LOG(VB_GENERAL, LOG_CRIT, QString("Found crashed database table(s): %1")
299  .arg(tables.join(", ")));
300  if (repair)
301  {
302  // If RepairTables() repairs the crashed tables, return true
303  result = RepairTables(tables);
304  }
305  else
306  {
307  result = false;
308  }
309  }
310 
311  return result;
312 }
313 
331 bool DBUtil::RepairTables(const QStringList &tables)
332 {
334  if (!query.isConnected())
335  return false;
336 
337  QString all_tables = tables.join(", ");
338  LOG(VB_GENERAL, LOG_CRIT, QString("Repairing database tables: %1")
339  .arg(all_tables));
340 
341  QString sql = QString("REPAIR TABLE %1;").arg(all_tables);
342  if (!query.exec(sql))
343  {
344  MythDB::DBError("DBUtil Repairing Tables", query);
345  return false;
346  }
347 
348  QStringList bad_tables = CheckRepairStatus(query);
349  bool result = true;
350  if (!bad_tables.empty())
351  {
352  LOG(VB_GENERAL, LOG_CRIT,
353  QString("Unable to repair crashed table(s): %1")
354  .arg(bad_tables.join(", ")));
355  result = false;
356  }
357  return result;
358 }
359 
379 {
380  QStringList tables;
381  QSqlRecord record = query.record();
382  int table_index = record.indexOf("Table");
383  int type_index = record.indexOf("Msg_type");
384  int text_index = record.indexOf("Msg_text");
385  QString table;
386  QString type;
387  QString text;
388  QString previous_table;
389  bool ok = true;
390  while (query.next())
391  {
392  table = query.value(table_index).toString();
393  type = query.value(type_index).toString();
394  text = query.value(text_index).toString();
395  if (table != previous_table)
396  {
397  if (!ok)
398  {
399  tables.append(previous_table);
400  ok = true;
401  }
402  previous_table = table;
403  }
404  // If the final row shows status OK, the table is now good
405  if ("status" == type.toLower() && "ok" == text.toLower())
406  ok = true;
407  else if ("error" == type.toLower() ||
408  ("status" == type.toLower() && "ok" != text.toLower()))
409  ok = false;
410  }
411  // Check the last table in the list
412  if (!ok)
413  tables.append(table);
414  return tables;
415 }
416 
422 QStringList DBUtil::GetTables(const QStringList &engines)
423 {
424  QStringList result;
425 
427  if (!query.isConnected())
428  return result;
429 
430  QString sql = "SELECT CONCAT('`', TABLE_SCHEMA, "
431  " '`.`', TABLE_NAME, "
432  " '`') AS `TABLE_NAME` "
433  " FROM INFORMATION_SCHEMA.TABLES "
434  " WHERE TABLE_SCHEMA = DATABASE() "
435  " AND TABLE_TYPE = 'BASE TABLE'";
436  if (!engines.empty())
437  sql.append(QString(" AND ENGINE IN ('%1')")
438  .arg(engines.join("', '")));
439  if (!query.exec(sql))
440  {
441  MythDB::DBError("DBUtil Finding Tables", query);
442  return result;
443  }
444 
445  while (query.next())
446  {
447  result.append(query.value(0).toString());
448  }
449 
450  return result;
451 }
452 
465 QString DBUtil::CreateBackupFilename(const QString& prefix, const QString& extension)
466 {
468  return QString("%1-%2%3").arg(prefix).arg(time).arg(extension);
469 }
470 
481 {
482  QString directory;
483  StorageGroup sgroup("DB Backups", gCoreContext->GetHostName());
484  QStringList dirList = sgroup.GetDirList();
485  if (!dirList.empty())
486  {
487  directory = sgroup.FindNextDirMostFree();
488 
489  if (!QDir(directory).exists())
490  {
491  LOG(VB_FILE, LOG_INFO, "GetBackupDirectory() - ignoring " +
492  directory + ", using /tmp");
493  directory.clear();
494  }
495  }
496 
497  if (directory.isNull())
498  {
499  // Rather than use kDefaultStorageDir, the default for
500  // FindNextDirMostFree() when no dirs are defined for the StorageGroup,
501  // use /tmp as it's possible that kDefaultStorageDir doesn't exist
502  // and (at least on *nix) less possible that /tmp doesn't exist
503  directory = "/tmp";
504  }
505 
506  return directory;
507 }
508 
518  const QString &privateinfo, QString &filename)
519 {
520  bool ok = true;
521  filename = createTempFile("/tmp/mythtv_db_backup_conf_XXXXXX");
522  const QByteArray tmpfile = filename.toLocal8Bit();
523 
524  FILE *fp = fopen(tmpfile.constData(), "w");
525  if (!fp)
526  {
527  LOG(VB_GENERAL, LOG_ERR, LOC +
528  QString("Unable to create temporary "
529  "configuration file for creating DB backup: %1")
530  .arg(tmpfile.constData()));
531  filename = "";
532  ok = false;
533  }
534  else
535  {
536  if (chmod(tmpfile.constData(), S_IRUSR))
537  {
538  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error changing permissions '%1'")
539  .arg(tmpfile.constData()) + ENO);
540  }
541 
542  QByteArray outarr = privateinfo.toLocal8Bit();
543  fprintf(fp, "%s", outarr.constData());
544 
545  if (fclose(fp))
546  {
547  LOG(VB_GENERAL, LOG_ERR, LOC + QString("Error closing '%1'")
548  .arg(tmpfile.constData()) + ENO);
549  }
550  }
551 
552  return ok;
553 }
554 
561 bool DBUtil::DoBackup(const QString &backupScript, QString &filename,
562  bool disableRotation)
563 {
565  QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
566  QString backupDirectory = GetBackupDirectory();
567  QString backupFilename = CreateBackupFilename(dbParams.m_dbName + "-" +
568  dbSchemaVer, ".sql");
569  QString scriptArgs = gCoreContext->GetSetting("BackupDBScriptArgs");
570  QString rotate = "";
571  if (disableRotation)
572  {
573  if (!(scriptArgs.contains("rotate", Qt::CaseInsensitive)))
574  rotate = "rotate=-1";
575  }
576 
577 
578  QString privateinfo =
579  QString("DBHostName=%1\nDBPort=%2\n"
580  "DBUserName=%3\nDBPassword=%4\n"
581  "DBName=%5\nDBSchemaVer=%6\n"
582  "DBBackupDirectory=%7\nDBBackupFilename=%8\n%9\n")
583  .arg(dbParams.m_dbHostName).arg(dbParams.m_dbPort)
584  .arg(dbParams.m_dbUserName).arg(dbParams.m_dbPassword)
585  .arg(dbParams.m_dbName).arg(dbSchemaVer)
586  .arg(backupDirectory).arg(backupFilename).arg(rotate);
587  QString tempDatabaseConfFile;
588  bool hastemp = CreateTemporaryDBConf(privateinfo, tempDatabaseConfFile);
589  if (!hastemp)
590  LOG(VB_GENERAL, LOG_ERR, LOC + "Attempting backup, anyway.");
591 
592  LOG(VB_GENERAL, LOG_ERR, QString("Backing up database with script: '%1'")
593  .arg(backupScript));
594 
595  QString command = backupScript + " " + scriptArgs + " " +
596  tempDatabaseConfFile;
598 
599  if (hastemp)
600  {
601  QByteArray tmpfile = tempDatabaseConfFile.toLocal8Bit();
602  unlink(tmpfile.constData());
603  }
604 
605  if (status != GENERIC_EXIT_OK)
606  {
607  LOG(VB_GENERAL, LOG_ERR, LOC +
608  QString("Error backing up database: %1 (%2)")
609  .arg(command).arg(status));
610  filename = "__FAILED__";
611  return false;
612  }
613 
614  LOG(VB_GENERAL, LOG_CRIT, "Database Backup complete.");
615 
616  QDir dir(backupDirectory, backupFilename + "*");
617  uint numfiles = dir.count();
618  if (numfiles < 1)
619  {
620  // If no file begins with the suggested filename, don't show the backup
621  // filename in the GUI message -- the script probably used some other
622  // filename
623  filename = "";
624  LOG(VB_FILE, LOG_ERR, LOC +
625  QString("No files beginning with the suggested database backup "
626  "filename '%1' were found in '%2'.")
627  .arg(backupFilename).arg(backupDirectory));
628  }
629  else
630  {
631  filename = dir.path() + "/" + dir[0];;
632  if (numfiles > 1)
633  {
634  LOG(VB_FILE, LOG_ERR, LOC +
635  QString("Multiple files beginning with the suggested database "
636  "backup filename '%1' were found in '%2'. "
637  "Assuming the first is the backup.")
638  .arg(backupFilename).arg(backupDirectory));
639  }
640  }
641 
642  if (!filename.isEmpty())
643  {
644  LOG(VB_GENERAL, LOG_CRIT, QString("Backed up database to file: '%1'")
645  .arg(filename));
646  }
647 
648  return true;
649 }
650 
658 {
660  QString dbSchemaVer = gCoreContext->GetSetting("DBSchemaVer");
661  QString backupDirectory = GetBackupDirectory();
662 
663  QString command;
664  QString compressCommand("");
665  QString extension = ".sql";
666  if (QFile::exists("/bin/gzip"))
667  compressCommand = "/bin/gzip";
668  else if (QFile::exists("/usr/bin/gzip"))
669  compressCommand = "/usr/bin/gzip";
670  else
671  LOG(VB_GENERAL, LOG_CRIT, "Neither /bin/gzip nor /usr/bin/gzip exist. "
672  "The database backup will be uncompressed.");
673 
674  QString backupFilename = CreateBackupFilename(
675  dbParams.m_dbName + "-" + dbSchemaVer, extension);
676  QString backupPathname = backupDirectory + "/" + backupFilename;
677 
678  QString privateinfo = QString(
679  "[client]\npassword=%1\n[mysqldump]\npassword=%2\n")
680  .arg(dbParams.m_dbPassword).arg(dbParams.m_dbPassword);
681  QString tempExtraConfFile;
682  if (!CreateTemporaryDBConf(privateinfo, tempExtraConfFile))
683  return false;
684 
685  QString portArg = "";
686  if (dbParams.m_dbPort > 0)
687  portArg = QString(" --port='%1'").arg(dbParams.m_dbPort);
688  command = QString("mysqldump --defaults-extra-file='%1' --host='%2'%3"
689  " --user='%4' --add-drop-table --add-locks"
690  " --allow-keywords --complete-insert"
691  " --extended-insert --lock-tables --no-create-db --quick"
692  " '%5' > '%6' 2>/dev/null")
693  .arg(tempExtraConfFile).arg(dbParams.m_dbHostName)
694  .arg(portArg).arg(dbParams.m_dbUserName)
695  .arg(dbParams.m_dbName).arg(backupPathname);
696 
697  LOG(VB_FILE, LOG_INFO, QString("Backing up database with command: '%1'")
698  .arg(command));
699  LOG(VB_GENERAL, LOG_CRIT, QString("Backing up database to file: '%1'")
700  .arg(backupPathname));
701 
703 
704  QByteArray tmpfile = tempExtraConfFile.toLocal8Bit();
705  unlink(tmpfile.constData());
706 
707  if (status != GENERIC_EXIT_OK)
708  {
709  LOG(VB_GENERAL, LOG_ERR, LOC +
710  QString("Error backing up database: '%1' (%2)")
711  .arg(command).arg(status));
712  filename = "__FAILED__";
713  return false;
714  }
715 
716  if (compressCommand != "")
717  {
718  LOG(VB_GENERAL, LOG_CRIT, "Compressing database backup file.");
719  compressCommand += " " + backupPathname;
720  status = myth_system(compressCommand, kMSDontBlockInputDevs);
721 
722  if (status != GENERIC_EXIT_OK)
723  {
724  LOG(VB_GENERAL, LOG_CRIT,
725  "Compression failed, backup file will remain uncompressed.");
726  }
727  else
728  {
729  backupPathname += ".gz";
730 
731  LOG(VB_GENERAL, LOG_CRIT, QString("Database Backup filename: '%1'")
732  .arg(backupPathname));
733  }
734  }
735 
736  LOG(VB_GENERAL, LOG_CRIT, "Database Backup complete.");
737 
738  filename = backupPathname;
739  return true;
740 }
741 
747 {
748  // Allow users to override the string provided by the database server in
749  // case the value was changed to an unrecognizable string by whomever
750  // compiled the MySQL server
751  QString dbmsVersion = gCoreContext->GetSetting("DBMSVersionOverride");
752 
753  if (dbmsVersion.isEmpty())
754  {
756  query.prepare("SELECT VERSION();");
757  if (!query.exec() || !query.next())
758  {
759  LOG(VB_GENERAL, LOG_ERR, LOC +
760  "Unable to determine MySQL version.");
761  MythDB::DBError("DBUtil Querying DBMS version", query);
762  dbmsVersion.clear();
763  }
764  else
765  dbmsVersion = query.value(0).toString();
766  }
767  m_versionString = dbmsVersion;
768 
769  return !m_versionString.isEmpty();
770 }
771 
776 {
777  if (m_versionString.isEmpty())
778  if (!QueryDBMSVersion())
779  return false;
780 
781  QString section;
782  int pos = 0;
783  int i = 0;
784  std::array<int,3> version = {-1, -1, -1};
785  QRegExp digits("(\\d+)");
786 
787  while ((i < 3) && ((pos = digits.indexIn(m_versionString, pos)) > -1))
788  {
789  bool ok = false;
790  section = digits.cap(1);
791  pos += digits.matchedLength();
792  version[i] = section.toInt(&ok, 10);
793  if (!ok)
794  version[i] = -1;
795  i++;
796  }
797 
798  m_versionMajor = version[0];
799  m_versionMinor = version[1];
800  m_versionPoint = version[2];
801 
802  return m_versionMajor > -1;
803 }
804 
809 {
810  int count = 0;
811 
813  if (!query.isConnected())
814  {
815  LOG(VB_GENERAL, LOG_DEBUG, "Not connected to DB");
816  return count;
817  }
818 
819  if (!query.exec("SHOW PROCESSLIST;"))
820  {
821  MythDB::DBError("DBUtil CountClients", query);
822  return count;
823  }
824 
825  QSqlRecord record = query.record();
826  int db_index = record.indexOf("db");
827  QString dbName = gCoreContext->GetDatabaseParams().m_dbName;
828  QString inUseDB;
829 
830  while (query.next())
831  {
832  inUseDB = query.value(db_index).toString();
833  if (inUseDB == dbName)
834  ++count;
835  }
836 
837  // On average, each myth program has 4 database connections,
838  // but we round up just in case a new program is loading:
839  count = (count + 3)/4;
840 
841  LOG(VB_GENERAL, LOG_DEBUG,
842  QString("DBUtil::CountClients() found %1").arg(count));
843 
844  return count;
845 }
846 
851 {
852  query.prepare("SELECT GET_LOCK('schemaLock', :TIMEOUT)");
853  query.bindValue(":TIMEOUT", timeout_secs);
854  return query.exec() && query.first() && query.value(0).toBool();
855 }
856 
858 {
859  query.prepare("SELECT RELEASE_LOCK('schemaLock')");
860  if (!query.exec())
861  {
862  MythDB::DBError("DBUtil UnlockSchema", query);
863  }
864 }
865 
870 {
872  query.prepare("SELECT CONVERT_TZ(NOW(), 'SYSTEM', 'Etc/UTC')");
873  if (!query.exec() || !query.next())
874  {
875  LOG(VB_GENERAL, LOG_ERR, "MySQL time zone support check failed");
876  return false;
877  }
878 
879  return !query.value(0).isNull();
880 }
881 
882 /* 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:746
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:126
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
myth_system
uint myth_system(const QString &command, uint flags, uint timeout)
Definition: mythsystemlegacy.cpp:501
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:21
dbutil.h
kMSDontBlockInputDevs
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
Definition: mythsystem.h:34
kMSAnonLog
@ kMSAnonLog
anonymize the logs
Definition: mythsystem.h:42
mythdb.h
DatabaseParams
Structure containing the basic Database parameters.
Definition: mythdbparams.h:10
MSqlQuery::record
QSqlRecord record(void) const
Definition: mythdbcon.h:205
DBUtil::CreateBackupFilename
static QString CreateBackupFilename(const QString &prefix="mythconverg", const QString &extension=".sql")
Creates a filename to use for the filename.
Definition: dbutil.cpp:465
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:198
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:273
MythCoreContext::GetDatabaseParams
DatabaseParams GetDatabaseParams(void)
Definition: mythcorecontext.h:140
mythdirs.h
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:775
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:23
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:378
DBUtil::CreateTemporaryDBConf
static bool CreateTemporaryDBConf(const QString &privateinfo, QString &filename)
Creates temporary file containing sensitive DB info.
Definition: dbutil.cpp:517
MythDate::kFilename
@ kFilename
Default UTC, "yyyyMMddhhmmss".
Definition: mythdate.h:15
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:365
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:185
DBUtil::CheckTimeZoneSupport
static bool CheckTimeZoneSupport(void)
Check if MySQL has working timz zone support.
Definition: dbutil.cpp:869
storagegroup.h
DBUtil::CountClients
static int CountClients(void)
Estimate the number of MythTV programs using the database.
Definition: dbutil.cpp:808
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:561
DatabaseParams::m_dbPassword
QString m_dbPassword
DB password.
Definition: mythdbparams.h:25
kDB_Backup_Failed
@ kDB_Backup_Failed
Definition: dbutil.h:12
DatabaseParams::m_dbName
QString m_dbName
database name
Definition: mythdbparams.h:26
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:135
uint
unsigned int uint
Definition: compat.h:140
MythDBBackupStatus
MythDBBackupStatus
Definition: dbutil.h:10
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:56
DBUtil::TryLockSchema
static bool TryLockSchema(MSqlQuery &query, uint timeout_secs)
Try to get a lock on the table schemalock.
Definition: dbutil.cpp:850
DBUtil::RepairTables
static bool RepairTables(const QStringList &tables)
Repairs database tables.
Definition: dbutil.cpp:331
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:923
mythmiscutil.h
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:480
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:24
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:12
MythDate::kDatabase
@ kDatabase
Default UTC, database format.
Definition: mythdate.h:24
DBUtil::UnlockSchema
static void UnlockSchema(MSqlQuery &query)
Definition: dbutil.cpp:857
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:855
exitcodes.h
DBUtil::GetTables
static QStringList GetTables(const QStringList &engines=QStringList())
Retrieves a list of tables from the database.
Definition: dbutil.cpp:422
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:908
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:915
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