MythTV
master
mythplugins
mythgame
mythgame
gamedbcheck.cpp
Go to the documentation of this file.
1
// C++
2
#include <iostream>
3
4
// Qt
5
#include <QString>
6
#include <QSqlError>
7
8
// MythTV
9
#include <
libmyth/mythcontext.h
>
10
#include <
libmythbase/mythdb.h
>
11
#include <
libmythbase/mythdbcheck.h
>
12
13
// MythGame
14
#include "
gamedbcheck.h
"
15
#include "
gamesettings.h
"
16
17
const
QString
currentDatabaseVersion
=
"1020"
;
18
const
QString
MythGameVersionName
=
"GameDBSchemaVer"
;
19
20
static
bool
InitializeDatabase
(
void
)
21
{
22
LOG
(VB_GENERAL, LOG_NOTICE,
23
"Inserting MythGame initial database information."
);
24
25
DBUpdates
updates {
26
"CREATE TABLE gamemetadata ("
27
" `system` varchar(128) NOT NULL default '',"
28
" romname varchar(128) NOT NULL default '',"
29
" gamename varchar(128) NOT NULL default '',"
30
" genre varchar(128) NOT NULL default '',"
31
" year varchar(10) NOT NULL default '',"
32
" publisher varchar(128) NOT NULL default '',"
33
" favorite tinyint(1) default NULL,"
34
" rompath varchar(255) NOT NULL default '',"
35
" gametype varchar(64) NOT NULL default '',"
36
" diskcount tinyint(1) NOT NULL default '1',"
37
" country varchar(128) NOT NULL default '',"
38
" crc_value varchar(64) NOT NULL default '',"
39
" display tinyint(1) NOT NULL default '1',"
40
" version varchar(64) NOT NULL default '',"
41
" KEY `system` (`system`),"
42
" KEY year (year),"
43
" KEY romname (romname),"
44
" KEY gamename (gamename),"
45
" KEY genre (genre)"
46
");"
,
47
"CREATE TABLE gameplayers ("
48
" gameplayerid int(10) unsigned NOT NULL auto_increment,"
49
" playername varchar(64) NOT NULL default '',"
50
" workingpath varchar(255) NOT NULL default '',"
51
" rompath varchar(255) NOT NULL default '',"
52
" screenshots varchar(255) NOT NULL default '',"
53
" commandline text NOT NULL,"
54
" gametype varchar(64) NOT NULL default '',"
55
" extensions varchar(128) NOT NULL default '',"
56
" spandisks tinyint(1) NOT NULL default '0',"
57
" PRIMARY KEY (gameplayerid),"
58
" UNIQUE KEY playername (playername)"
59
");"
,
60
"CREATE TABLE romdb ("
61
" crc varchar(64) NOT NULL default '',"
62
" name varchar(128) NOT NULL default '',"
63
" description varchar(128) NOT NULL default '',"
64
" category varchar(128) NOT NULL default '',"
65
" year varchar(10) NOT NULL default '',"
66
" manufacturer varchar(128) NOT NULL default '',"
67
" country varchar(128) NOT NULL default '',"
68
" publisher varchar(128) NOT NULL default '',"
69
" platform varchar(64) NOT NULL default '',"
70
" filesize int(12) default NULL,"
71
" flags varchar(64) NOT NULL default '',"
72
" version varchar(64) NOT NULL default '',"
73
" KEY crc (crc),"
74
" KEY year (year),"
75
" KEY category (category),"
76
" KEY name (name),"
77
" KEY description (description),"
78
" KEY platform (platform)"
79
");"
80
};
81
QString dbver =
""
;
82
return
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
83
updates,
"1011"
, dbver);
84
}
85
86
bool
UpgradeGameDatabaseSchema
(
void
)
87
{
88
QString dbver =
gCoreContext
->
GetSetting
(
"GameDBSchemaVer"
);
89
MSqlQuery
query(
MSqlQuery::InitCon
());
90
91
if
(dbver ==
currentDatabaseVersion
)
92
return
true
;
93
94
if
(dbver.isEmpty())
95
{
96
if
(!
InitializeDatabase
())
97
return
false
;
98
dbver =
"1011"
;
99
}
100
101
if
(dbver ==
"1000"
)
102
{
103
DBUpdates
updates {
104
"ALTER TABLE gamemetadata ADD COLUMN favorite BOOL NULL;"
105
};
106
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
107
updates,
"1001"
, dbver))
108
return
false
;
109
}
110
111
if
((((dbver ==
"1004"
)
112
|| (dbver ==
"1003"
))
113
|| (dbver ==
"1002"
))
114
|| (dbver ==
"1001"
))
115
{
116
DBUpdates
updates {
117
118
"CREATE TABLE gameplayers ("
119
" gameplayerid int(10) unsigned NOT NULL auto_increment,"
120
" playername varchar(64) NOT NULL default '',"
121
" workingpath varchar(255) NOT NULL default '',"
122
" rompath varchar(255) NOT NULL default '',"
123
" screenshots varchar(255) NOT NULL default '',"
124
" commandline varchar(255) NOT NULL default '',"
125
" gametype varchar(64) NOT NULL default '',"
126
" extensions varchar(128) NOT NULL default '',"
127
" PRIMARY KEY (gameplayerid),"
128
" UNIQUE KEY playername (playername)"
129
");"
,
130
"ALTER TABLE gamemetadata ADD COLUMN rompath varchar(255) NOT NULL default ''; "
,
131
"ALTER TABLE gamemetadata ADD COLUMN gametype varchar(64) NOT NULL default ''; "
132
};
133
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
134
updates,
"1005"
, dbver))
135
return
false
;
136
}
137
138
if
(dbver ==
"1005"
)
139
{
140
DBUpdates
updates {
141
"ALTER TABLE gameplayers ADD COLUMN spandisks tinyint(1) NOT NULL default 0; "
,
142
"ALTER TABLE gamemetadata ADD COLUMN diskcount tinyint(1) NOT NULL default 1; "
143
};
144
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
145
updates,
"1006"
, dbver))
146
return
false
;
147
}
148
149
if
(dbver ==
"1006"
)
150
{
151
152
if
(!
gCoreContext
->
GetSetting
(
"GameAllTreeLevels"
).isEmpty())
153
{
154
if
(!query.
exec
(
"UPDATE settings SET data = 'system gamename' "
155
"WHERE value = 'GameAllTreeLevels'; "
))
156
MythDB::DBError
(
"update GameAllTreeLevels"
, query);
157
}
158
159
DBUpdates
updates = {
160
"ALTER TABLE gamemetadata ADD COLUMN country varchar(128) NOT NULL default ''; "
,
161
"ALTER TABLE gamemetadata ADD COLUMN crc_value varchar(64) NOT NULL default ''; "
,
162
"ALTER TABLE gamemetadata ADD COLUMN display tinyint(1) NOT NULL default 1; "
163
};
164
165
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
166
updates,
"1007"
, dbver))
167
return
false
;
168
}
169
170
if
(dbver ==
"1007"
)
171
{
172
DBUpdates
updates {
173
"ALTER TABLE gameplayers MODIFY commandline TEXT NOT NULL default ''; "
174
};
175
176
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
177
updates,
"1008"
, dbver))
178
return
false
;
179
}
180
181
if
(dbver ==
"1008"
)
182
{
183
DBUpdates
updates {
184
"CREATE TABLE romdb ("
185
" crc varchar(64) NOT NULL default '',"
186
" name varchar(128) NOT NULL default '',"
187
" description varchar(128) NOT NULL default '',"
188
" category varchar(128) NOT NULL default '',"
189
" year varchar(10) NOT NULL default '',"
190
" manufacturer varchar(128) NOT NULL default '',"
191
" country varchar(128) NOT NULL default '',"
192
" publisher varchar(128) NOT NULL default '',"
193
" platform varchar(64) NOT NULL default '',"
194
" filesize int(12) default NULL,"
195
" flags varchar(64) NOT NULL default '',"
196
" version varchar(64) NOT NULL default '',"
197
" KEY crc (crc),"
198
" KEY year (year),"
199
" KEY category (category),"
200
" KEY name (name),"
201
" KEY description (description),"
202
" KEY platform (platform)"
203
");"
204
};
205
206
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
207
updates,
"1009"
, dbver))
208
return
false
;
209
}
210
211
if
(dbver ==
"1009"
)
212
{
213
DBUpdates
updates {
214
"ALTER TABLE gamemetadata MODIFY year varchar(10) not null default '';"
215
};
216
217
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
218
updates,
"1010"
, dbver))
219
return
false
;
220
}
221
222
if
(dbver ==
"1010"
)
223
{
224
DBUpdates
updates {
225
226
"ALTER TABLE gamemetadata ADD COLUMN version varchar(64) NOT NULL default '';"
,
227
"ALTER TABLE gamemetadata ADD COLUMN publisher varchar(128) NOT NULL default '';"
228
};
229
230
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
231
updates,
"1011"
, dbver))
232
return
false
;
233
}
234
235
236
if
(dbver ==
"1011"
)
237
{
238
DBUpdates
updates {
239
"ALTER TABLE romdb ADD COLUMN binfile varchar(64) NOT NULL default ''; "
240
};
241
242
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
243
updates,
"1012"
, dbver))
244
return
false
;
245
}
246
247
248
if
(dbver ==
"1012"
)
249
{
250
DBUpdates
updates {
251
qPrintable(QString(
"ALTER DATABASE %1 DEFAULT CHARACTER SET latin1;"
)
252
.arg(
GetMythDB
()->GetDatabaseName())),
253
"ALTER TABLE gamemetadata"
254
" MODIFY `system` varbinary(128) NOT NULL default '',"
255
" MODIFY romname varbinary(128) NOT NULL default '',"
256
" MODIFY gamename varbinary(128) NOT NULL default '',"
257
" MODIFY genre varbinary(128) NOT NULL default '',"
258
" MODIFY year varbinary(10) NOT NULL default '',"
259
" MODIFY publisher varbinary(128) NOT NULL default '',"
260
" MODIFY rompath varbinary(255) NOT NULL default '',"
261
" MODIFY gametype varbinary(64) NOT NULL default '',"
262
" MODIFY country varbinary(128) NOT NULL default '',"
263
" MODIFY crc_value varbinary(64) NOT NULL default '',"
264
" MODIFY version varbinary(64) NOT NULL default '';"
,
265
"ALTER TABLE gameplayers"
266
" MODIFY playername varbinary(64) NOT NULL default '',"
267
" MODIFY workingpath varbinary(255) NOT NULL default '',"
268
" MODIFY rompath varbinary(255) NOT NULL default '',"
269
" MODIFY screenshots varbinary(255) NOT NULL default '',"
270
" MODIFY commandline blob NOT NULL,"
271
" MODIFY gametype varbinary(64) NOT NULL default '',"
272
" MODIFY extensions varbinary(128) NOT NULL default '';"
,
273
"ALTER TABLE romdb"
274
" MODIFY crc varbinary(64) NOT NULL default '',"
275
" MODIFY name varbinary(128) NOT NULL default '',"
276
" MODIFY description varbinary(128) NOT NULL default '',"
277
" MODIFY category varbinary(128) NOT NULL default '',"
278
" MODIFY year varbinary(10) NOT NULL default '',"
279
" MODIFY manufacturer varbinary(128) NOT NULL default '',"
280
" MODIFY country varbinary(128) NOT NULL default '',"
281
" MODIFY publisher varbinary(128) NOT NULL default '',"
282
" MODIFY platform varbinary(64) NOT NULL default '',"
283
" MODIFY flags varbinary(64) NOT NULL default '',"
284
" MODIFY version varbinary(64) NOT NULL default '',"
285
" MODIFY binfile varbinary(64) NOT NULL default '';"
286
};
287
288
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
289
updates,
"1013"
, dbver))
290
return
false
;
291
}
292
293
294
if
(dbver ==
"1013"
)
295
{
296
DBUpdates
updates {
297
qPrintable(QString(
"ALTER DATABASE %1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
)
298
.arg(
GetMythDB
()->GetDatabaseName())),
299
"ALTER TABLE gamemetadata"
300
" DEFAULT CHARACTER SET utf8,"
301
" MODIFY `system` varchar(128) CHARACTER SET utf8 NOT NULL default '',"
302
" MODIFY romname varchar(128) CHARACTER SET utf8 NOT NULL default '',"
303
" MODIFY gamename varchar(128) CHARACTER SET utf8 NOT NULL default '',"
304
" MODIFY genre varchar(128) CHARACTER SET utf8 NOT NULL default '',"
305
" MODIFY year varchar(10) CHARACTER SET utf8 NOT NULL default '',"
306
" MODIFY publisher varchar(128) CHARACTER SET utf8 NOT NULL default '',"
307
" MODIFY rompath varchar(255) CHARACTER SET utf8 NOT NULL default '',"
308
" MODIFY gametype varchar(64) CHARACTER SET utf8 NOT NULL default '',"
309
" MODIFY country varchar(128) CHARACTER SET utf8 NOT NULL default '',"
310
" MODIFY crc_value varchar(64) CHARACTER SET utf8 NOT NULL default '',"
311
" MODIFY version varchar(64) CHARACTER SET utf8 NOT NULL default '';"
,
312
"ALTER TABLE gameplayers"
313
" DEFAULT CHARACTER SET utf8,"
314
" MODIFY playername varchar(64) CHARACTER SET utf8 NOT NULL default '',"
315
" MODIFY workingpath varchar(255) CHARACTER SET utf8 NOT NULL default '',"
316
" MODIFY rompath varchar(255) CHARACTER SET utf8 NOT NULL default '',"
317
" MODIFY screenshots varchar(255) CHARACTER SET utf8 NOT NULL default '',"
318
" MODIFY commandline text CHARACTER SET utf8 NOT NULL,"
319
" MODIFY gametype varchar(64) CHARACTER SET utf8 NOT NULL default '',"
320
" MODIFY extensions varchar(128) CHARACTER SET utf8 NOT NULL default '';"
,
321
"ALTER TABLE romdb"
322
" DEFAULT CHARACTER SET utf8,"
323
" MODIFY crc varchar(64) CHARACTER SET utf8 NOT NULL default '',"
324
" MODIFY name varchar(128) CHARACTER SET utf8 NOT NULL default '',"
325
" MODIFY description varchar(128) CHARACTER SET utf8 NOT NULL default '',"
326
" MODIFY category varchar(128) CHARACTER SET utf8 NOT NULL default '',"
327
" MODIFY year varchar(10) CHARACTER SET utf8 NOT NULL default '',"
328
" MODIFY manufacturer varchar(128) CHARACTER SET utf8 NOT NULL default '',"
329
" MODIFY country varchar(128) CHARACTER SET utf8 NOT NULL default '',"
330
" MODIFY publisher varchar(128) CHARACTER SET utf8 NOT NULL default '',"
331
" MODIFY platform varchar(64) CHARACTER SET utf8 NOT NULL default '',"
332
" MODIFY flags varchar(64) CHARACTER SET utf8 NOT NULL default '',"
333
" MODIFY version varchar(64) CHARACTER SET utf8 NOT NULL default '',"
334
" MODIFY binfile varchar(64) CHARACTER SET utf8 NOT NULL default '';"
335
};
336
337
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
338
updates,
"1014"
, dbver))
339
return
false
;
340
}
341
342
if
(dbver ==
"1014"
)
343
{
344
DBUpdates
updates {
345
346
"ALTER TABLE gamemetadata ADD fanart VARCHAR(255) NOT NULL AFTER rompath,"
347
"ADD boxart VARCHAR( 255 ) NOT NULL AFTER fanart;"
348
};
349
350
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
351
updates,
"1015"
, dbver))
352
return
false
;
353
}
354
355
if
(dbver ==
"1015"
)
356
{
357
DBUpdates
updates {
358
359
"ALTER TABLE gamemetadata ADD screenshot VARCHAR(255) NOT NULL AFTER rompath,"
360
"ADD plot TEXT NOT NULL AFTER fanart;"
361
};
362
363
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
364
updates,
"1016"
, dbver))
365
return
false
;
366
}
367
368
if
(dbver ==
"1016"
)
369
{
370
DBUpdates
updates {
371
372
"ALTER TABLE gamemetadata ADD inetref TEXT AFTER crc_value;"
373
};
374
375
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
376
updates,
"1017"
, dbver))
377
return
false
;
378
}
379
380
if
(dbver ==
"1017"
)
381
{
382
DBUpdates
updates {
383
384
"ALTER TABLE gamemetadata ADD intid int(11) NOT NULL AUTO_INCREMENT "
385
"PRIMARY KEY FIRST;"
386
};
387
388
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
389
updates,
"1018"
, dbver))
390
return
false
;
391
}
392
393
if
(dbver ==
"1018"
)
394
{
395
DBUpdates
updates {
396
"ALTER TABLE romdb MODIFY description varchar(192) CHARACTER SET utf8 NOT NULL default '';"
,
397
"ALTER TABLE romdb MODIFY binfile varchar(128) CHARACTER SET utf8 NOT NULL default '';"
,
398
"ALTER TABLE romdb MODIFY filesize int(12) unsigned default NULL;"
399
};
400
401
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
402
updates,
"1019"
, dbver))
403
return
false
;
404
}
405
406
// Repeat 1013 DBs pre MySQL v8 systems that may have not be set to utf8
407
408
if
(dbver ==
"1019"
)
409
{
410
DBUpdates
updates {
411
"ALTER TABLE gamemetadata DEFAULT CHARACTER SET utf8;"
,
412
"ALTER TABLE gameplayers DEFAULT CHARACTER SET utf8;"
,
413
"ALTER TABLE romdb DEFAULT CHARACTER SET utf8;"
414
};
415
416
if
(!
performActualUpdate
(
"MythGame"
,
MythGameVersionName
,
417
updates,
"1020"
, dbver))
418
return
false
;
419
}
420
421
return
true
;
422
423
}
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition:
mythdbcon.h:127
mythdb.h
InitializeDatabase
static bool InitializeDatabase(void)
Definition:
gamedbcheck.cpp:20
gamedbcheck.h
UpgradeGameDatabaseSchema
bool UpgradeGameDatabaseSchema(void)
Definition:
gamedbcheck.cpp:86
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition:
mythdbcon.cpp:618
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition:
mythlogging.h:39
GetMythDB
MythDB * GetMythDB(void)
Definition:
mythdb.cpp:50
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition:
mythdbcon.cpp:550
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition:
mythdb.cpp:225
mythdbcheck.h
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition:
mythcorecontext.cpp:55
MythGameVersionName
const QString MythGameVersionName
Definition:
gamedbcheck.cpp:18
gamesettings.h
performActualUpdate
bool performActualUpdate(const QString &component, const QString &versionkey, const DBUpdates &updates, const QString &version, QString &dbver)
Definition:
dbcheckcommon.cpp:113
currentDatabaseVersion
const QString currentDatabaseVersion
Definition:
gamedbcheck.cpp:17
mythcontext.h
DBUpdates
std::vector< std::string > DBUpdates
Definition:
mythdbcheck.h:9
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition:
mythcorecontext.cpp:902
Generated on Sun Jan 5 2025 03:16:11 for MythTV by
1.8.17