MythTV master
videodbcheck.cpp
Go to the documentation of this file.
1/* Integrates the MythVideo DB schema into the core MythTV DB schema. Used
2 * only by DB update 1267. Any further changes to the core MythTV schema,
3 * including changes to those parts that were previously MythVideo, should
4 * be done in mythtv/libs/libmythtv/dbcheck.cpp. */
5
6#include <QString>
7#include <QStringList>
8
10#include "libmythbase/mythdb.h"
16
17#include "videodbcheck.h"
18
19const QString minimumVideoDatabaseVersion = "1016";
20const QString finalVideoDatabaseVersion = "1038";
21const QString MythVideoVersionName = "mythvideo.DBSchemaVer";
22
23static void AddFileType(const QString &extension,
24 const QString &playCommand = QString("Internal"),
25 bool ignored = false, bool useDefault = false)
26{
28 query.prepare("SELECT * FROM videotypes WHERE "
29 "LOWER(extension) = LOWER(:EXTENSION) LIMIT 1");
30 query.bindValue(":EXTENSION", extension);
31 if (query.exec() && !query.size())
32 {
33 query.prepare("INSERT INTO videotypes (extension, playcommand, "
34 "f_ignore, use_default) VALUES (:EXTENSION, :PLAYCOMMAND, "
35 ":IGNORE, :USEDEFAULT)");
36 query.bindValue(":EXTENSION", extension);
37 query.bindValue(":PLAYCOMMAND", playCommand);
38 query.bindValue(":IGNORE", ignored);
39 query.bindValue(":USEDEFAULT", useDefault);
40 if (!query.exec())
41 MythDB::DBError(QObject::tr("Error: failed to add new file "
42 "type '%1'").arg(extension), query);
43 }
44}
45
46static void UpdateHashes(void)
47{
49 query.prepare("SELECT `filename`, `host` FROM videometadata WHERE "
50 "`hash` = \"\"");
51 if (query.exec() && query.size())
52 {
53 while (query.next())
54 {
55 QString filename = query.value(0).toString();
56 QString host = query.value(1).toString();
57 QString hash;
58
59 if (!host.isEmpty())
60 {
61 QString url = StorageGroup::generate_file_url("Videos", host, filename);
62 hash = RemoteFile::GetFileHash(url);
63 }
64 else
65 {
66 hash = FileHash(filename);
67 }
68
69 if (hash == "NULL")
70 hash = QString();
71
72 MSqlQuery updatequery(MSqlQuery::InitCon());
73
74 updatequery.prepare("UPDATE videometadata set `hash` = :HASH "
75 "WHERE `filename` = :FILENAME AND "
76 "`host` = :HOST");
77 updatequery.bindValue(":HASH", hash);
78 updatequery.bindValue(":FILENAME", filename);
79 updatequery.bindValue(":HOST", host);
80 if (!updatequery.exec())
81 {
82 MythDB::DBError(QObject::tr("Error: failed to hash file "
83 "'%1'").arg(filename), updatequery);
84 }
85 else
86 {
87 LOG(VB_GENERAL, LOG_INFO,
88 QString("Hash (%1) generated for file (%2)")
89 .arg(hash, filename));
90 }
91 }
92 }
93}
94
95static bool InitializeVideoSchema(void)
96{
98 LOG(VB_GENERAL, LOG_NOTICE,
99 "Inserting initial video database information.");
100
101 DBUpdates updates {
102"CREATE TABLE dvdinput ("
103" intid int(10) unsigned NOT NULL,"
104" hsize int(10) unsigned DEFAULT NULL,"
105" vsize int(10) unsigned DEFAULT NULL,"
106" ar_num int(10) unsigned DEFAULT NULL,"
107" ar_denom int(10) unsigned DEFAULT NULL,"
108" fr_code int(10) unsigned DEFAULT NULL,"
109" letterbox tinyint(1) DEFAULT NULL,"
110" v_format varchar(16) DEFAULT NULL,"
111" PRIMARY KEY (intid)"
112") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
113"CREATE TABLE dvdtranscode ("
114" intid int(11) NOT NULL AUTO_INCREMENT,"
115" input int(10) unsigned DEFAULT NULL,"
116" `name` varchar(128) NOT NULL,"
117" sync_mode int(10) unsigned DEFAULT NULL,"
118" use_yv12 tinyint(1) DEFAULT NULL,"
119" cliptop int(11) DEFAULT NULL,"
120" clipbottom int(11) DEFAULT NULL,"
121" clipleft int(11) DEFAULT NULL,"
122" clipright int(11) DEFAULT NULL,"
123" f_resize_h int(11) DEFAULT NULL,"
124" f_resize_w int(11) DEFAULT NULL,"
125" hq_resize_h int(11) DEFAULT NULL,"
126" hq_resize_w int(11) DEFAULT NULL,"
127" grow_h int(11) DEFAULT NULL,"
128" grow_w int(11) DEFAULT NULL,"
129" clip2top int(11) DEFAULT NULL,"
130" clip2bottom int(11) DEFAULT NULL,"
131" clip2left int(11) DEFAULT NULL,"
132" clip2right int(11) DEFAULT NULL,"
133" codec varchar(128) NOT NULL,"
134" codec_param varchar(128) DEFAULT NULL,"
135" bitrate int(11) DEFAULT NULL,"
136" a_sample_r int(11) DEFAULT NULL,"
137" a_bitrate int(11) DEFAULT NULL,"
138" two_pass tinyint(1) DEFAULT NULL,"
139" tc_param varchar(128) DEFAULT NULL,"
140" PRIMARY KEY (intid)"
141") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
142"CREATE TABLE filemarkup ("
143" filename text NOT NULL,"
144" mark mediumint(8) unsigned NOT NULL DEFAULT '0',"
145" `offset` bigint(20) unsigned DEFAULT NULL,"
146" `type` tinyint(4) NOT NULL DEFAULT '0',"
147" KEY filename (filename(255))"
148") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
149"CREATE TABLE videocast ("
150" intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
151" cast varchar(128) NOT NULL,"
152" PRIMARY KEY (intid)"
153") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
154"CREATE TABLE videocategory ("
155" intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
156" category varchar(128) NOT NULL,"
157" PRIMARY KEY (intid)"
158") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
159"CREATE TABLE videocountry ("
160" intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
161" country varchar(128) NOT NULL,"
162" PRIMARY KEY (intid)"
163") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
164"CREATE TABLE videogenre ("
165" intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
166" genre varchar(128) NOT NULL,"
167" PRIMARY KEY (intid)"
168") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
169"CREATE TABLE videometadata ("
170" intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
171" title varchar(128) NOT NULL,"
172" subtitle text NOT NULL,"
173" tagline varchar(255) DEFAULT NULL,"
174" director varchar(128) NOT NULL,"
175" studio varchar(128) DEFAULT NULL,"
176" plot text,"
177" rating varchar(128) NOT NULL,"
178" inetref varchar(255) NOT NULL,"
179" homepage text NOT NULL,"
180" `year` int(10) unsigned NOT NULL,"
181" releasedate date NOT NULL,"
182" userrating float NOT NULL,"
183" length int(10) unsigned NOT NULL,"
184" season smallint(5) unsigned NOT NULL DEFAULT '0',"
185" episode smallint(5) unsigned NOT NULL DEFAULT '0',"
186" showlevel int(10) unsigned NOT NULL,"
187" filename text NOT NULL,"
188" `hash` varchar(128) NOT NULL,"
189" coverfile text NOT NULL,"
190" childid int(11) NOT NULL DEFAULT '-1',"
191" browse tinyint(1) NOT NULL DEFAULT '1',"
192" watched tinyint(1) NOT NULL DEFAULT '0',"
193" processed tinyint(1) NOT NULL DEFAULT '0',"
194" playcommand varchar(255) DEFAULT NULL,"
195" category int(10) unsigned NOT NULL DEFAULT '0',"
196" trailer text,"
197" `host` text NOT NULL,"
198" screenshot text,"
199" banner text,"
200" fanart text,"
201" insertdate timestamp NULL DEFAULT CURRENT_TIMESTAMP,"
202" PRIMARY KEY (intid),"
203" KEY director (director),"
204" KEY title (title)"
205") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
206"CREATE TABLE videometadatacast ("
207" idvideo int(10) unsigned NOT NULL,"
208" idcast int(10) unsigned NOT NULL,"
209" UNIQUE KEY idvideo (idvideo,idcast)"
210") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
211"CREATE TABLE videometadatacountry ("
212" idvideo int(10) unsigned NOT NULL,"
213" idcountry int(10) unsigned NOT NULL,"
214" UNIQUE KEY idvideo_2 (idvideo,idcountry),"
215" KEY idvideo (idvideo),"
216" KEY idcountry (idcountry)"
217") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
218"CREATE TABLE videometadatagenre ("
219" idvideo int(10) unsigned NOT NULL,"
220" idgenre int(10) unsigned NOT NULL,"
221" UNIQUE KEY idvideo_2 (idvideo,idgenre),"
222" KEY idvideo (idvideo),"
223" KEY idgenre (idgenre)"
224") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
225"CREATE TABLE videotypes ("
226" intid int(10) unsigned NOT NULL AUTO_INCREMENT,"
227" extension varchar(128) NOT NULL,"
228" playcommand varchar(255) NOT NULL,"
229" f_ignore tinyint(1) DEFAULT NULL,"
230" use_default tinyint(1) DEFAULT NULL,"
231" PRIMARY KEY (intid)"
232") ENGINE=MyISAM DEFAULT CHARSET=utf8;",
233"INSERT INTO dvdinput VALUES (1,720,480,16,9,1,1,'ntsc');",
234"INSERT INTO dvdinput VALUES (2,720,480,16,9,1,0,'ntsc');",
235"INSERT INTO dvdinput VALUES (3,720,480,4,3,1,1,'ntsc');",
236"INSERT INTO dvdinput VALUES (4,720,480,4,3,1,0,'ntsc');",
237"INSERT INTO dvdinput VALUES (5,720,576,16,9,3,1,'pal');",
238"INSERT INTO dvdinput VALUES (6,720,576,16,9,3,0,'pal');",
239"INSERT INTO dvdinput VALUES (7,720,576,4,3,3,1,'pal');",
240"INSERT INTO dvdinput VALUES (8,720,576,4,3,3,0,'pal');",
241"INSERT INTO dvdtranscode VALUES (1,1,'Good',2,1,16,16,0,0,2,0,0,0,0,0,32,32,8,8,'divx5',NULL,1618,NULL,NULL,0,NULL);",
242"INSERT INTO dvdtranscode VALUES (2,2,'Excellent',2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'divx5',NULL,0,NULL,NULL,1,NULL);",
243"INSERT INTO dvdtranscode VALUES (3,2,'Good',2,1,0,0,8,8,0,0,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
244"INSERT INTO dvdtranscode VALUES (4,2,'Medium',2,1,0,0,8,8,5,5,0,0,0,0,0,0,0,0,'divx5',NULL,1200,NULL,NULL,0,NULL);",
245"INSERT INTO dvdtranscode VALUES (5,3,'Good',2,1,0,0,0,0,0,0,0,0,2,0,80,80,8,8,'divx5',NULL,0,NULL,NULL,0,NULL);",
246"INSERT INTO dvdtranscode VALUES (6,4,'Excellent',2,1,0,0,0,0,0,0,0,0,2,0,0,0,0,0,'divx5',NULL,0,NULL,NULL,1,NULL);",
247"INSERT INTO dvdtranscode VALUES (7,4,'Good',2,1,0,0,8,8,0,2,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
248"INSERT INTO dvdtranscode VALUES (8,5,'Good',1,1,16,16,0,0,5,0,0,0,0,0,40,40,8,8,'divx5',NULL,1618,NULL,NULL,0,NULL);",
249"INSERT INTO dvdtranscode VALUES (9,6,'Good',1,1,0,0,16,16,5,0,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
250"INSERT INTO dvdtranscode VALUES (10,7,'Good',1,1,0,0,0,0,1,0,0,0,0,0,76,76,8,8,'divx5',NULL,1618,NULL,NULL,0,NULL);",
251"INSERT INTO dvdtranscode VALUES (11,8,'Good',1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,'divx5',NULL,1618,NULL,NULL,0,NULL);",
252"INSERT INTO videotypes VALUES (1,'txt','',1,0);",
253"INSERT INTO videotypes VALUES (2,'log','',1,0);",
254"INSERT INTO videotypes VALUES (3,'mpg','Internal',0,0);",
255"INSERT INTO videotypes VALUES (4,'avi','',0,1);",
256"INSERT INTO videotypes VALUES (5,'vob','Internal',0,0);",
257"INSERT INTO videotypes VALUES (6,'mpeg','Internal',0,0);",
258"INSERT INTO videotypes VALUES (8,'iso','Internal',0,0);",
259"INSERT INTO videotypes VALUES (9,'img','Internal',0,0);",
260"INSERT INTO videotypes VALUES (10,'mkv','Internal',0,0);",
261"INSERT INTO videotypes VALUES (11,'mp4','Internal',0,0);",
262"INSERT INTO videotypes VALUES (12,'m2ts','Internal',0,0);",
263"INSERT INTO videotypes VALUES (13,'evo','Internal',0,0);",
264"INSERT INTO videotypes VALUES (14,'divx','Internal',0,0);",
265"INSERT INTO videotypes VALUES (15,'mov','Internal',0,0);",
266"INSERT INTO videotypes VALUES (16,'qt','Internal',0,0);",
267"INSERT INTO videotypes VALUES (17,'wmv','Internal',0,0);",
268"INSERT INTO videotypes VALUES (18,'3gp','Internal',0,0);",
269"INSERT INTO videotypes VALUES (19,'asf','Internal',0,0);",
270"INSERT INTO videotypes VALUES (20,'ogg','Internal',0,0);",
271"INSERT INTO videotypes VALUES (21,'ogm','Internal',0,0);",
272"INSERT INTO videotypes VALUES (22,'flv','Internal',0,0);",
273"INSERT INTO videotypes VALUES (23,'ogv','Internal',0,0);",
274"INSERT INTO videotypes VALUES (25,'nut','Internal',0,0);",
275"INSERT INTO videotypes VALUES (26,'mxf','Internal',0,0);",
276"INSERT INTO videotypes VALUES (27,'m4v','Internal',0,0);",
277"INSERT INTO videotypes VALUES (28,'rm','Internal',0,0);",
278"INSERT INTO videotypes VALUES (29,'ts','Internal',0,0);",
279"INSERT INTO videotypes VALUES (30,'swf','Internal',0,0);",
280"INSERT INTO videotypes VALUES (31,'f4v','Internal',0,0);",
281"INSERT INTO videotypes VALUES (32,'nuv','Internal',0,0);"
282};
283
284 QString dbver = "";
285 return performActualUpdate("MythVideo", MythVideoVersionName,
286 updates, finalVideoDatabaseVersion, dbver);
287}
288
290{
291 QString dbver = gCoreContext->GetSetting("mythvideo.DBSchemaVer");
292 if (dbver == finalVideoDatabaseVersion)
293 {
294 return true;
295 }
296
297 QString olddbver = gCoreContext->GetSetting("VideoDBSchemaVer");
298 QString dvddbver = gCoreContext->GetSetting("DVDDBSchemaVer");
299 if (dbver.isEmpty() && olddbver.isEmpty() && dvddbver.isEmpty())
300 {
302 return false;
303 dbver = gCoreContext->GetSetting("mythvideo.DBSchemaVer");
304 }
305
306 if (dbver.isEmpty() || dbver.toInt() < minimumVideoDatabaseVersion.toInt())
307 {
308 LOG(VB_GENERAL, LOG_ERR,
309 "Unrecognized video database schema version. "
310 "Unable to upgrade database.");
311 LOG(VB_GENERAL, LOG_ERR, QString("mythvideo.DBSchemaVer: '%1', "
312 "VideoDBSchemaVer: '%2', DVDDBSchemaVer: '%3'")
313 .arg(dbver, olddbver, dvddbver));
314 return false;
315 }
316
317 if (dbver == "1016")
318 {
319 DBUpdates updates {
320// NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
321"ALTER TABLE dvdbookmark"
322" MODIFY serialid varbinary(16) NOT NULL default '',"
323" MODIFY name varbinary(32) default NULL;",
324"ALTER TABLE dvdinput"
325" MODIFY v_format varbinary(16) default NULL;",
326"ALTER TABLE dvdtranscode"
327" MODIFY name varbinary(128) NOT NULL,"
328" MODIFY codec varbinary(128) NOT NULL,"
329" MODIFY codec_param varbinary(128) default NULL,"
330" MODIFY tc_param varbinary(128) default NULL;",
331"ALTER TABLE filemarkup"
332" MODIFY filename blob NOT NULL;",
333"ALTER TABLE videocast"
334" MODIFY cast varbinary(128) NOT NULL;",
335"ALTER TABLE videocategory"
336" MODIFY category varbinary(128) NOT NULL;",
337"ALTER TABLE videocountry"
338" MODIFY country varbinary(128) NOT NULL;",
339"ALTER TABLE videogenre"
340" MODIFY genre varbinary(128) NOT NULL;",
341"ALTER TABLE videometadata"
342" MODIFY title varbinary(128) NOT NULL,"
343" MODIFY director varbinary(128) NOT NULL,"
344" MODIFY plot blob,"
345" MODIFY rating varbinary(128) NOT NULL,"
346" MODIFY inetref varbinary(255) NOT NULL,"
347" MODIFY filename blob NOT NULL,"
348" MODIFY coverfile blob NOT NULL,"
349" MODIFY playcommand varbinary(255) default NULL;",
350"ALTER TABLE videotypes"
351" MODIFY extension varbinary(128) NOT NULL,"
352" MODIFY playcommand varbinary(255) NOT NULL;"
353};
354
356 updates, "1017", dbver))
357 return false;
358 }
359
360
361 if (dbver == "1017")
362 {
363 DBUpdates updates {
364// NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
365"ALTER TABLE dvdbookmark"
366" DEFAULT CHARACTER SET default,"
367" MODIFY serialid varchar(16) CHARACTER SET utf8 NOT NULL default '',"
368" MODIFY name varchar(32) CHARACTER SET utf8 default NULL;",
369"ALTER TABLE dvdinput"
370" DEFAULT CHARACTER SET default,"
371" MODIFY v_format varchar(16) CHARACTER SET utf8 default NULL;",
372"ALTER TABLE dvdtranscode"
373" DEFAULT CHARACTER SET default,"
374" MODIFY name varchar(128) CHARACTER SET utf8 NOT NULL,"
375" MODIFY codec varchar(128) CHARACTER SET utf8 NOT NULL,"
376" MODIFY codec_param varchar(128) CHARACTER SET utf8 default NULL,"
377" MODIFY tc_param varchar(128) CHARACTER SET utf8 default NULL;",
378"ALTER TABLE filemarkup"
379" DEFAULT CHARACTER SET default,"
380" MODIFY filename text CHARACTER SET utf8 NOT NULL;",
381"ALTER TABLE videocast"
382" DEFAULT CHARACTER SET default,"
383" MODIFY cast varchar(128) CHARACTER SET utf8 NOT NULL;",
384"ALTER TABLE videocategory"
385" DEFAULT CHARACTER SET default,"
386" MODIFY category varchar(128) CHARACTER SET utf8 NOT NULL;",
387"ALTER TABLE videocountry"
388" DEFAULT CHARACTER SET default,"
389" MODIFY country varchar(128) CHARACTER SET utf8 NOT NULL;",
390"ALTER TABLE videogenre"
391" DEFAULT CHARACTER SET default,"
392" MODIFY genre varchar(128) CHARACTER SET utf8 NOT NULL;",
393"ALTER TABLE videometadata"
394" DEFAULT CHARACTER SET default,"
395" MODIFY title varchar(128) CHARACTER SET utf8 NOT NULL,"
396" MODIFY director varchar(128) CHARACTER SET utf8 NOT NULL,"
397" MODIFY plot text CHARACTER SET utf8,"
398" MODIFY rating varchar(128) CHARACTER SET utf8 NOT NULL,"
399" MODIFY inetref varchar(255) CHARACTER SET utf8 NOT NULL,"
400" MODIFY filename text CHARACTER SET utf8 NOT NULL,"
401" MODIFY coverfile text CHARACTER SET utf8 NOT NULL,"
402" MODIFY playcommand varchar(255) CHARACTER SET utf8 default NULL;",
403"ALTER TABLE videometadatacast"
404" DEFAULT CHARACTER SET default;",
405"ALTER TABLE videometadatacountry"
406" DEFAULT CHARACTER SET default;",
407"ALTER TABLE videometadatagenre"
408" DEFAULT CHARACTER SET default;",
409"ALTER TABLE videotypes"
410" DEFAULT CHARACTER SET default,"
411" MODIFY extension varchar(128) CHARACTER SET utf8 NOT NULL,"
412" MODIFY playcommand varchar(255) CHARACTER SET utf8 NOT NULL;"
413};
414
416 updates, "1018", dbver))
417 return false;
418 }
419
420 if (dbver == "1018")
421 {
422 DBUpdates updates {
423 "DELETE FROM settings WHERE value="
424 "'MovieListCommandLine' AND data LIKE '%imdb%';",
425 "DELETE FROM settings WHERE value="
426 "'MovieDataCommandLine' AND data LIKE '%imdb%';",
427 "DELETE FROM settings WHERE value="
428 "'MoviePosterCommandLine' AND data LIKE '%imdb%';"
429 };
431 updates, "1019", dbver))
432 return false;
433 }
434
435 if (dbver == "1019")
436 {
437 DBUpdates updates {
438 "ALTER TABLE videometadata ADD `trailer` TEXT;"
439 };
441 updates, "1020", dbver))
442 return false;
443 }
444
445 if (dbver == "1020")
446 {
447 LOG(VB_GENERAL, LOG_NOTICE,
448 "Upgrading to MythVideo schema version 1021");
449
450 AddFileType("mkv");
451 AddFileType("mp4");
452 AddFileType("m2ts");
453 AddFileType("evo");
454 AddFileType("divx");
455 AddFileType("mov");
456 AddFileType("qt");
457 AddFileType("wmv");
458 AddFileType("3gp");
459 AddFileType("asf");
460 AddFileType("ogg");
461 AddFileType("ogm");
462 AddFileType("flv");
463
464 if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1021", dbver))
465 return false;
466 }
467
468 if (dbver == "1021")
469 {
470 DBUpdates updates {
471 "ALTER TABLE videometadata ADD host text CHARACTER SET utf8 NOT NULL;"
472 };
473
475 updates, "1022", dbver))
476 return false;
477 }
478
479 if (dbver == "1022")
480 {
481 DBUpdates updates {
482 "ALTER TABLE videometadata ADD `screenshot` TEXT;",
483 "ALTER TABLE videometadata ADD `banner` TEXT;",
484 "ALTER TABLE videometadata ADD `fanart` TEXT;"
485 };
487 updates, "1023", dbver))
488 return false;
489 }
490
491 if (dbver == "1023")
492 {
493 DBUpdates updates {
494 "ALTER TABLE videometadata ADD `subtitle` TEXT "
495 "NOT NULL AFTER `title`;",
496 "ALTER TABLE videometadata ADD `season` SMALLINT "
497 "UNSIGNED NOT NULL DEFAULT '0' AFTER `length`;",
498 "ALTER TABLE videometadata ADD `episode` SMALLINT "
499 "UNSIGNED NOT NULL DEFAULT '0' AFTER `season`;"
500 };
502 updates, "1024", dbver))
503 return false;
504 }
505
506 if (dbver == "1024")
507 {
508 DBUpdates updates {
509 "ALTER TABLE videometadata ADD watched BOOL "
510 "NOT NULL DEFAULT 0 AFTER browse;"
511 };
513 updates, "1025", dbver))
514 return false;
515 }
516
517 if (dbver == "1025")
518 {
519 DBUpdates updates {
520 "ALTER TABLE videometadata ADD `insertdate` TIMESTAMP "
521 "NULL DEFAULT CURRENT_TIMESTAMP AFTER `fanart`;"
522 };
524 updates, "1026", dbver))
525 return false;
526 }
527
528 if (dbver == "1026")
529 {
530 DBUpdates updates {
531 "DELETE FROM keybindings "
532 " WHERE action = 'DELETE' AND context = 'Video';"
533 };
535 updates, "1027", dbver))
536 return false;
537 }
538
539 if (dbver == "1027")
540 {
541 LOG(VB_GENERAL, LOG_NOTICE,
542 "Upgrading to MythVideo schema version 1028");
543 LOG(VB_GENERAL, LOG_INFO,
544 "Converting filenames in filemarkup table "
545 "from absolute to relative paths. This may take a long "
546 "time if you have a large number of MythVideo seektables.");
547
548 bool ok = true;
551
552 query.prepare("SELECT DISTINCT filename FROM filemarkup;");
553 update.prepare("UPDATE filemarkup SET filename = :RELPATH "
554 " WHERE filename = :FULLPATH;");
555 if (query.exec())
556 {
557 QString origPath;
558 QString relPath;
559 while (query.next())
560 {
561 origPath = query.value(0).toString();
562 if (origPath.startsWith("dvd:"))
563 continue;
564
565 relPath = StorageGroup::GetRelativePathname(origPath);
566 if ((!relPath.isEmpty()) &&
567 (relPath != origPath))
568 {
569 update.bindValue(":RELPATH", relPath);
570 update.bindValue(":FULLPATH", origPath);
571 if (!update.exec())
572 {
573 LOG(VB_GENERAL, LOG_ERR,
574 QString("ERROR converting '%1' to '%2' in "
575 "filemarkup table.")
576 .arg(origPath, relPath));
577 ok = false;
578 }
579 }
580 }
581 }
582 else
583 {
584 ok = false;
585 }
586
587 if (!ok)
588 return false;
589
590 if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1028", dbver))
591 return false;
592 }
593
594 if (dbver == "1028")
595 {
596 DBUpdates updates {
597 "ALTER TABLE videometadata ADD `releasedate` DATE "
598 "NOT NULL AFTER `year`;",
599 "ALTER TABLE videometadata ADD `homepage` TEXT "
600 "NOT NULL AFTER `inetref`;"
601 };
603 updates, "1029", dbver))
604 return false;
605 }
606
607 if (dbver == "1029")
608 {
609 DBUpdates updates {
610 "ALTER TABLE videometadata ADD `hash` VARCHAR(128) "
611 "NOT NULL AFTER `filename`;"
612 };
614 updates, "1030", dbver))
615 return false;
616 }
617
618 if (dbver == "1030")
619 {
620 UpdateHashes();
621 if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1031", dbver))
622 return false;
623 }
624
625 if (dbver == "1031")
626 {
628 query.prepare("SHOW INDEX FROM videometadata");
629
630 if (!query.exec())
631 {
632 MythDB::DBError("Unable to retrieve current indices on "
633 "videometadata.", query);
634 }
635 else
636 {
637 while (query.next())
638 {
639 QString index_name = query.value(2).toString();
640
641 if ("title_2" == index_name)
642 {
644 update.prepare("ALTER TABLE videometadata "
645 " DROP INDEX title_2");
646
647 if (!update.exec())
648 {
649 MythDB::DBError("Unable to drop duplicate index "
650 "on videometadata. Ignoring.",
651 update);
652 }
653 break;
654 }
655 }
656 }
657
658 if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1032", dbver))
659 return false;
660 }
661
662 if (dbver == "1032")
663 {
664 DBUpdates updates {
665 // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
666 "CREATE TEMPORARY TABLE bad_videometadatacast"
667 " AS SELECT * FROM videometadatacast,",
668 "CREATE TEMPORARY TABLE bad_videometadatagenre"
669 " AS SELECT * FROM videometadatagenre,",
670 "CREATE TEMPORARY TABLE bad_videometadatacountry"
671 " AS SELECT * FROM videometadatacountry,",
672 "TRUNCATE TABLE videometadatacast,",
673 "TRUNCATE TABLE videometadatagenre,",
674 "TRUNCATE TABLE videometadatacountry,",
675 "INSERT videometadatacast SELECT idvideo,idcast"
676 " FROM bad_videometadatacast GROUP BY idvideo,idcast,",
677 "INSERT videometadatagenre SELECT idvideo,idgenre"
678 " FROM bad_videometadatagenre GROUP BY idvideo,idgenre,",
679 "INSERT videometadatacountry SELECT idvideo,idcountry"
680 " FROM bad_videometadatacountry GROUP BY idvideo,idcountry,",
681 "DROP TEMPORARY TABLE bad_videometadatacast,",
682 "DROP TEMPORARY TABLE bad_videometadatagenre,",
683 "DROP TEMPORARY TABLE bad_videometadatacountry,",
684 "ALTER TABLE videometadatacast ADD UNIQUE INDEX (`idvideo`,`idcast`),",
685 "ALTER TABLE videometadatagenre ADD UNIQUE INDEX (`idvideo`,`idgenre`),",
686 "ALTER TABLE videometadatacountry ADD UNIQUE INDEX (`idvideo`,`idcountry`);"
687 };
689 updates, "1033", dbver))
690 return false;
691
692 dbver = "1033";
693 }
694
695 if (dbver == "1033")
696 {
697 AddFileType("ogv");
698 AddFileType("BDMV");
699 AddFileType("nut");
700 AddFileType("mxf");
701 AddFileType("m4v");
702 AddFileType("rm");
703 AddFileType("ts");
704 AddFileType("swf");
705 AddFileType("f4v");
706 AddFileType("nuv");
707
708 if (!UpdateDBVersionNumber("MythVideo", MythVideoVersionName, "1034", dbver))
709 return false;
710 }
711
712 if (dbver == "1034")
713 {
714 DBUpdates updates {
715 "ALTER TABLE videometadata ADD `tagline` VARCHAR (255) "
716 "AFTER `subtitle`;"
717 };
718
720 updates, "1035", dbver))
721 return false;
722 }
723
724 if (dbver == "1035")
725 {
726 DBUpdates updates {
727 "ALTER TABLE videometadata ADD processed BOOL "
728 "NOT NULL DEFAULT 0 AFTER watched;"
729 };
731 updates, "1036", dbver))
732 return false;
733 }
734
735 if (dbver == "1036")
736 {
737 DBUpdates updates {
738 "ALTER TABLE videometadata ADD `studio` VARCHAR( 128 ) "
739 "AFTER `director`;"
740 };
742 updates, "1037", dbver))
743 return false;
744 }
745
746 if (dbver == "1037")
747 {
748 DBUpdates updates {
749 "DELETE FROM videotypes WHERE extension = 'VIDEO_TS';",
750 "DELETE FROM videotypes WHERE extension = 'BDMV';"
751 };
753 updates, "1038", dbver))
754 return false;
755 }
756
757 return true;
758}
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
QVariant value(int i) const
Definition: mythdbcon.h:204
int size(void) const
Definition: mythdbcon.h:214
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
QString GetSetting(const QString &key, const QString &defaultval="")
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
static QString GetFileHash(const QString &url)
Definition: remotefile.cpp:553
static QString generate_file_url(const QString &storage_group, const QString &host, const QString &path)
static QString GetRelativePathname(const QString &filename)
Returns the relative pathname of a file by comparing the filename against all Storage Group directori...
bool performActualUpdate(const QString &component, const QString &versionkey, const DBUpdates &updates, const QString &version, QString &dbver)
bool UpdateDBVersionNumber(const QString &component, const QString &versionkey, const QString &newnumber, QString &dbver)
Updates the schema version stored in the database.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
std::vector< std::string > DBUpdates
Definition: mythdbcheck.h:9
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QString FileHash(const QString &filename)
bool doUpgradeVideoDatabaseSchema(void)
const QString minimumVideoDatabaseVersion
static bool InitializeVideoSchema(void)
static void AddFileType(const QString &extension, const QString &playCommand=QString("Internal"), bool ignored=false, bool useDefault=false)
const QString MythVideoVersionName
static void UpdateHashes(void)
const QString finalVideoDatabaseVersion