MythTV  master
Macros | Functions | Variables
mythtv/libs/libmythtv/dbcheck.cpp File Reference
#include "mythconfig.h"
#include <cstdio>
#include <iostream>
#include <QString>
#include <QSqlError>
#include "dbcheck.h"
#include "mythversion.h"
#include "dbutil.h"
#include "mythcorecontext.h"
#include "schemawizard.h"
#include "mythdb.h"
#include "mythlogging.h"
#include "videodbcheck.h"
#include "compat.h"
#include "recordingrule.h"
#include "recordingprofile.h"
#include "recordinginfo.h"
#include "cardutil.h"
#include "videodisplayprofile.h"
Include dependency graph for mythtv/libs/libmythtv/dbcheck.cpp:

Go to the source code of this file.

Macros

#define MINIMUM_DBMS_VERSION   5,0,15
 
#define db_sd_notify(x)
 

Functions

static bool UpdateDBVersionNumber (const QString &newnumber, QString &dbver)
 Updates the schema version stored in the database. More...
 
static bool performActualUpdate (const char **updates, const char *version, QString &dbver)
 Runs a number of SQL commands, and updates the schema version. More...
 
static bool doUpgradeTVDatabaseSchema (void)
 This is called by UpgradeTVDatabaseSchema() to actually upgrade the schema to what MythTV expects. More...
 
static bool performUpdateSeries (const char **updates)
 Runs a number of SQL commands. More...
 
bool UpgradeTVDatabaseSchema (const bool upgradeAllowed, const bool upgradeIfNoUI, const bool informSystemd)
 Called from outside dbcheck.cpp to update the schema. More...
 
bool InitializeMythSchema (void)
 command to get the the initial database layout from an empty database: More...
 

Variables

const QString currentDatabaseVersion = MYTH_DATABASE_VERSION
 

Macro Definition Documentation

◆ MINIMUM_DBMS_VERSION

#define MINIMUM_DBMS_VERSION   5,0,15

Definition at line 27 of file mythtv/libs/libmythtv/dbcheck.cpp.

◆ db_sd_notify

#define db_sd_notify (   x)

Definition at line 42 of file mythtv/libs/libmythtv/dbcheck.cpp.

Function Documentation

◆ UpdateDBVersionNumber()

static bool UpdateDBVersionNumber ( const QString &  newnumber,
QString &  dbver 
)
static

Updates the schema version stored in the database.

Updates "DBSchemaVer" property in the settings table.

Parameters
newnumberNew schema version.
dbverthe database version at the end of the function is returned in this parameter, if things go well this will be 'newnumber'.

Definition at line 357 of file mythtv/libs/libmythtv/dbcheck.cpp.

Referenced by doUpgradeTVDatabaseSchema(), and performActualUpdate().

◆ performActualUpdate()

static bool performActualUpdate ( const char **  updates,
const char *  version,
QString &  dbver 
)
static

Runs a number of SQL commands, and updates the schema version.

Parameters
updatesarray of SQL commands to issue, terminated by a NULL string.
versionversion we are updating db to.
dbverthe database version at the end of the function is returned in this parameter, if things go well this will be 'version'.
Returns
true on success, false on failure

Definition at line 441 of file mythtv/libs/libmythtv/dbcheck.cpp.

Referenced by doUpgradeTVDatabaseSchema(), and InitializeMythSchema().

◆ doUpgradeTVDatabaseSchema()

static bool doUpgradeTVDatabaseSchema ( void  )
static

This is called by UpgradeTVDatabaseSchema() to actually upgrade the schema to what MythTV expects.

This function Initializes the database if the "DBSchemaVer" property does not exist in the database. Otherwise it upgrades the schema from the one in that property to the currentDatabaseVersion, by running the SQL commands needed for each upgrade between the two versions. This will only upgrade the schema, so bad things may happen if you upgrade and then downgrade MythTV across DB Schema versions.

Definition at line 577 of file mythtv/libs/libmythtv/dbcheck.cpp.

Referenced by UpgradeTVDatabaseSchema().

◆ performUpdateSeries()

performUpdateSeries ( const char **  updates)
static

Runs a number of SQL commands.

Parameters
updatesarray of SQL commands to issue, terminated by a NULL string.
Returns
true on success, false on failure

Definition at line 405 of file mythtv/libs/libmythtv/dbcheck.cpp.

Referenced by doUpgradeTVDatabaseSchema(), and performActualUpdate().

◆ UpgradeTVDatabaseSchema()

bool UpgradeTVDatabaseSchema ( const bool  upgradeAllowed,
const bool  upgradeIfNoUI,
const bool  informSystemd 
)

Called from outside dbcheck.cpp to update the schema.

If the "DBSchemaVer" property equals the currentDatabase version this returns true immediately. If not, we try to do a database backup, if interactive prompt the user for permission to do the upgrade, and if permitted or non-interactive with a successful backup do the actual update.

If the program running this function is killed while this is running then the schema may be corrupted.

Returns
false on failure, error, or if the user selected "Exit."

Definition at line 472 of file mythtv/libs/libmythtv/dbcheck.cpp.

Referenced by main(), and run_backend().

◆ InitializeMythSchema()

bool InitializeMythSchema ( void  )

command to get the the initial database layout from an empty database:

mysqldump \ –skip-comments –skip-opt –compact –skip-quote-names \ –create-options –ignore-table=mythconverg.schemalock mythconverg | \ sed '/^(SET|INS).*;$/d;/^\/*!40101.*$/d;s/^.*[^;]$/"&"/;s/^).*;$/"&",/'

command to get the initial data:

mysqldump \ –skip-comments –skip-opt –compact –skip-quote-names -t \ –ignore-table=mythconverg.logging mythconverg | sed -e 's/^.*$/"&",/' -e 's#\#\\#g'

don't forget to delete host specific data

Definition at line 3723 of file mythtv/libs/libmythtv/dbcheck.cpp.

Referenced by doUpgradeTVDatabaseSchema(), and main().

Variable Documentation

◆ currentDatabaseVersion

const QString currentDatabaseVersion = MYTH_DATABASE_VERSION