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
8 #include <mythcontext.h>
9 #include <mythdb.h>
10 #include <mythdbcheck.h>
11 
12 // mytharchive
13 #include "archivedbcheck.h"
14 
15 const QString currentDatabaseVersion = "1005";
16 const QString MythArchiveVersionName = "ArchiveDBSchemaVer";
17 
19 {
20  QString dbver = gCoreContext->GetSetting("ArchiveDBSchemaVer");
21 
22  if (dbver == currentDatabaseVersion)
23  return true;
24 
25  if (dbver == "")
26  {
27  LOG(VB_GENERAL, LOG_INFO,
28  "Inserting MythArchive initial database information.");
29 
30  DBUpdates updates
31  {
32  "DROP TABLE IF EXISTS archiveitems;",
33 
34  "CREATE TABLE IF NOT EXISTS archiveitems ("
35  " intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
36  " type set ('Recording','Video','File'),"
37  " title VARCHAR(128),"
38  " subtitle VARCHAR(128),"
39  " description TEXT,"
40  " startdate VARCHAR(30),"
41  " starttime VARCHAR(30),"
42  " size INT UNSIGNED NOT NULL,"
43  " filename TEXT NOT NULL,"
44  " hascutlist BOOL NOT NULL DEFAULT 0,"
45  " cutlist TEXT,"
46  " INDEX (title)"
47  ");"
48  };
49  if (!performActualUpdate("MythArchive", MythArchiveVersionName,
50  updates, "1000", dbver))
51  return false;
52  }
53 
54  if (dbver == "1000")
55  {
56  DBUpdates updates
57  {
58  "ALTER TABLE archiveitems MODIFY size BIGINT UNSIGNED NOT NULL;"
59  };
60 
61  if (!performActualUpdate("MythArchive", MythArchiveVersionName,
62  updates, "1001", dbver))
63  return false;
64  }
65 
66 
67  if (dbver == "1001")
68  {
69  DBUpdates updates
70  {
71  qPrintable(QString("ALTER DATABASE %1 DEFAULT CHARACTER SET latin1;")
73  "ALTER TABLE archiveitems"
74  " MODIFY title varbinary(128) default NULL,"
75  " MODIFY subtitle varbinary(128) default NULL,"
76  " MODIFY description blob,"
77  " MODIFY startdate varbinary(30) default NULL,"
78  " MODIFY starttime varbinary(30) default NULL,"
79  " MODIFY filename blob,"
80  " MODIFY cutlist blob;"
81  };
82 
83  if (!performActualUpdate("MythArchive", MythArchiveVersionName,
84  updates, "1002", dbver))
85  return false;
86  }
87 
88 
89  if (dbver == "1002")
90  {
91  DBUpdates updates
92  {
93  qPrintable(QString("ALTER DATABASE %1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;")
95  "ALTER TABLE archiveitems"
96  " DEFAULT CHARACTER SET default,"
97  " MODIFY title varchar(128) CHARACTER SET utf8 default NULL,"
98  " MODIFY subtitle varchar(128) CHARACTER SET utf8 default NULL,"
99  " MODIFY description text CHARACTER SET utf8,"
100  " MODIFY startdate varchar(30) CHARACTER SET utf8 default NULL,"
101  " MODIFY starttime varchar(30) CHARACTER SET utf8 default NULL,"
102  " MODIFY filename text CHARACTER SET utf8 NOT NULL,"
103  " MODIFY cutlist text CHARACTER SET utf8;"
104  };
105 
106  if (!performActualUpdate("MythArchive", MythArchiveVersionName,
107  updates, "1003", dbver))
108  return false;
109  }
110 
111  if (dbver == "1003")
112  {
113  DBUpdates updates
114  {
115  "ALTER TABLE `archiveitems` "
116  "ADD duration INT UNSIGNED NOT NULL DEFAULT 0, "
117  "ADD cutduration INT UNSIGNED NOT NULL DEFAULT 0, "
118  "ADD videowidth INT UNSIGNED NOT NULL DEFAULT 0, "
119  "ADD videoheight INT UNSIGNED NOT NULL DEFAULT 0, "
120  "ADD filecodec VARCHAR(50) NOT NULL DEFAULT '', "
121  "ADD videocodec VARCHAR(50) NOT NULL DEFAULT '', "
122  "ADD encoderprofile VARCHAR(50) NOT NULL DEFAULT 'NONE';"
123  };
124 
125  if (!performActualUpdate("MythArchive", MythArchiveVersionName,
126  updates, "1004", dbver))
127  return false;
128  }
129 
130  if (dbver == "1004")
131  {
132  DBUpdates updates
133  {
134  "DELETE FROM keybindings "
135  " WHERE action = 'DELETEITEM' AND context = 'Archive';"
136  };
137 
138  if (!performActualUpdate("MythArchive", MythArchiveVersionName,
139  updates, "1005", dbver))
140  return false;
141  }
142 
143  return true;
144 }
145 
mythdb.h
MythContext::GetDatabaseParams
DatabaseParams GetDatabaseParams(void)
Definition: mythcontext.cpp:1677
MythArchiveVersionName
const QString MythArchiveVersionName
Definition: archivedbcheck.cpp:16
arg
arg(title).arg(filename).arg(doDelete))
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythdbcheck.h
DatabaseParams::m_dbName
QString m_dbName
database name
Definition: mythdbparams.h:26
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
performActualUpdate
bool performActualUpdate(const QString &component, const QString &versionkey, const DBUpdates &updates, const QString &version, QString &dbver)
Definition: dbcheckcommon.cpp:113
archivedbcheck.h
currentDatabaseVersion
const QString currentDatabaseVersion
Definition: archivedbcheck.cpp:15
mythcontext.h
UpgradeArchiveDatabaseSchema
bool UpgradeArchiveDatabaseSchema(void)
Definition: archivedbcheck.cpp:18
DBUpdates
std::vector< std::string > DBUpdates
Definition: mythdbcheck.h:9
gContext
MythContext * gContext
This global variable contains the MythContext instance for the application.
Definition: mythcontext.cpp:64
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919