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