MythTV master
archivedbcheck.cpp
Go to the documentation of this file.
1#include <iostream>
2
3// Qt
4#include <QString>
5#include <QSqlError>
6
7// MythTV
12
13// mytharchive
14#include "archivedbcheck.h"
15
16const QString currentDatabaseVersion = "1006";
17const QString MythArchiveVersionName = "ArchiveDBSchemaVer";
18
20{
21 QString dbver = gCoreContext->GetSetting("ArchiveDBSchemaVer");
22
23 if (dbver == currentDatabaseVersion)
24 return true;
25
26 if (dbver == "")
27 {
28 LOG(VB_GENERAL, LOG_INFO,
29 "Inserting MythArchive initial database information.");
30
31 DBUpdates updates
32 {
33 "DROP TABLE IF EXISTS archiveitems;",
34
35 "CREATE TABLE IF NOT EXISTS archiveitems ("
36 " intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
37 " type set ('Recording','Video','File'),"
38 " title VARCHAR(128),"
39 " subtitle VARCHAR(128),"
40 " description TEXT,"
41 " startdate VARCHAR(30),"
42 " starttime VARCHAR(30),"
43 " size INT UNSIGNED NOT NULL,"
44 " filename TEXT NOT NULL,"
45 " hascutlist BOOL NOT NULL DEFAULT 0,"
46 " cutlist TEXT,"
47 " INDEX (title)"
48 ");"
49 };
51 updates, "1000", dbver))
52 return false;
53 }
54
55 if (dbver == "1000")
56 {
57 DBUpdates updates
58 {
59 "ALTER TABLE archiveitems MODIFY size BIGINT UNSIGNED NOT NULL;"
60 };
61
63 updates, "1001", dbver))
64 return false;
65 }
66
67
68 if (dbver == "1001")
69 {
70 DBUpdates updates
71 {
72 qPrintable(QString("ALTER DATABASE %1 DEFAULT CHARACTER SET latin1;")
73 .arg(GetMythDB()->GetDatabaseName())),
74 "ALTER TABLE archiveitems"
75 " MODIFY title varbinary(128) default NULL,"
76 " MODIFY subtitle varbinary(128) default NULL,"
77 " MODIFY description blob,"
78 " MODIFY startdate varbinary(30) default NULL,"
79 " MODIFY starttime varbinary(30) default NULL,"
80 " MODIFY filename blob,"
81 " MODIFY cutlist blob;"
82 };
83
85 updates, "1002", dbver))
86 return false;
87 }
88
89
90 if (dbver == "1002")
91 {
92 DBUpdates updates
93 {
94 qPrintable(QString("ALTER DATABASE %1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;")
95 .arg(GetMythDB()->GetDatabaseName())),
96 "ALTER TABLE archiveitems"
97 " DEFAULT CHARACTER SET utf8,"
98 " MODIFY title varchar(128) CHARACTER SET utf8 NULL,"
99 " MODIFY subtitle varchar(128) CHARACTER SET utf8 NULL,"
100 " MODIFY description text CHARACTER SET utf8,"
101 " MODIFY startdate varchar(30) CHARACTER SET utf8 NULL,"
102 " MODIFY starttime varchar(30) CHARACTER SET utf8 NULL,"
103 " MODIFY filename text CHARACTER SET utf8 NOT NULL,"
104 " MODIFY cutlist text CHARACTER SET utf8;"
105 };
106
108 updates, "1003", dbver))
109 return false;
110 }
111
112 if (dbver == "1003")
113 {
114 DBUpdates updates
115 {
116 "ALTER TABLE `archiveitems` "
117 "ADD duration INT UNSIGNED NOT NULL DEFAULT 0, "
118 "ADD cutduration INT UNSIGNED NOT NULL DEFAULT 0, "
119 "ADD videowidth INT UNSIGNED NOT NULL DEFAULT 0, "
120 "ADD videoheight INT UNSIGNED NOT NULL DEFAULT 0, "
121 "ADD filecodec VARCHAR(50) NOT NULL DEFAULT '', "
122 "ADD videocodec VARCHAR(50) NOT NULL DEFAULT '', "
123 "ADD encoderprofile VARCHAR(50) NOT NULL DEFAULT 'NONE';"
124 };
125
127 updates, "1004", dbver))
128 return false;
129 }
130
131 if (dbver == "1004")
132 {
133 DBUpdates updates
134 {
135 "DELETE FROM keybindings "
136 " WHERE action = 'DELETEITEM' AND context = 'Archive';"
137 };
138
140 updates, "1005", dbver))
141 return false;
142 }
143
144 // Repeat 1003 DBs pre MySQL v8 systems that may have not be set to utf8
145
146 if (dbver == "1005")
147 {
148 DBUpdates updates
149 {
150 "ALTER TABLE archiveitems"
151 " DEFAULT CHARACTER SET utf8,"
152 " MODIFY title varchar(128) CHARACTER SET utf8 NULL,"
153 " MODIFY subtitle varchar(128) CHARACTER SET utf8 NULL,"
154 " MODIFY startdate varchar(30) CHARACTER SET utf8 NULL,"
155 " MODIFY starttime varchar(30) CHARACTER SET utf8 NULL;"
156 };
157
159 updates, "1006", dbver))
160 return false;
161 }
162
163 return true;
164}
165
const QString currentDatabaseVersion
const QString MythArchiveVersionName
bool UpgradeArchiveDatabaseSchema(void)
QString GetSetting(const QString &key, const QString &defaultval="")
bool performActualUpdate(const QString &component, const QString &versionkey, const DBUpdates &updates, const QString &version, QString &dbver)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythDB * GetMythDB(void)
Definition: mythdb.cpp:51
std::vector< std::string > DBUpdates
Definition: mythdbcheck.h:9
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39