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