00001 #include <qstring.h>
00002 #include <qregexp.h>
00003 #include <qstringlist.h>
00004
00005 #include <mythtv/mythcontext.h>
00006 #include <mythtv/mythdbcon.h>
00007
00008 #include "dbcheck.h"
00009 #include "videodlg.h"
00010
00011 namespace
00012 {
00013 const QString lastMythDVDDBVersion = "1002";
00014 const QString lastMythVideoVersion = "1010";
00015
00016 const QString currentDatabaseVersion = "1016";
00017
00018 const QString OldMythVideoVersionName = "VideoDBSchemaVer";
00019 const QString OldMythDVDVersionName = "DVDDBSchemaVer";
00020
00021 const QString MythVideoVersionName = "mythvideo.DBSchemaVer";
00022
00023 void UpdateDBVersionNumber(const QString &field_name,
00024 const QString &newnumber)
00025 {
00026 MSqlQuery query(MSqlQuery::InitCon());
00027
00028 query.exec(QString("DELETE FROM settings WHERE value='%1';")
00029 .arg(field_name));
00030 query.exec(QString("INSERT INTO settings (value, data, hostname) "
00031 "VALUES ('%1', %2, NULL);")
00032 .arg(field_name).arg(newnumber));
00033 }
00034
00035 void performActualUpdate(const QStringList &updates, const QString &version,
00036 QString &dbver, const QString &field_name)
00037 {
00038 MSqlQuery query(MSqlQuery::InitCon());
00039
00040 VERBOSE(VB_IMPORTANT,
00041 QString("Upgrading to MythVideo schema version %1")
00042 .arg(version));
00043
00044 for (QStringList::const_iterator p = updates.begin();
00045 p != updates.end(); ++p)
00046 {
00047 query.exec(*p);
00048 }
00049
00050 UpdateDBVersionNumber(field_name, version);
00051 dbver = version;
00052 }
00053
00054 void performActualUpdate(const QString updates[], const QString &version,
00055 QString &dbver, const QString &field_name)
00056 {
00057 QStringList upQuery;
00058 for (int i = 0; ; ++i)
00059 {
00060 QString q = updates[i];
00061 if (q == "") break;
00062 upQuery.append(q);
00063 }
00064 performActualUpdate(upQuery, version, dbver, field_name);
00065 }
00066
00067 void InitializeVideoDatabase()
00068 {
00069 VERBOSE(VB_IMPORTANT,
00070 "Inserting MythVideo initial database information.");
00071
00072 const QString updates[] = {
00073 "CREATE TABLE IF NOT EXISTS videometadata ("
00074 " intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00075 " title VARCHAR(128) NOT NULL,"
00076 " director VARCHAR(128) NOT NULL,"
00077 " plot VARCHAR(255) NOT NULL,"
00078 " rating VARCHAR(128) NOT NULL,"
00079 " inetref VARCHAR(32) NOT NULL,"
00080 " year INT UNSIGNED NOT NULL,"
00081 " userrating FLOAT NOT NULL,"
00082 " length INT UNSIGNED NOT NULL,"
00083 " showlevel INT UNSIGNED NOT NULL,"
00084 " filename TEXT NOT NULL,"
00085 " coverfile TEXT NOT NULL,"
00086 " childid INT NOT NULL DEFAULT -1,"
00087 " browse BOOL NOT NULL DEFAULT 1,"
00088 " playcommand VARCHAR(255),"
00089 " INDEX (director),"
00090 " INDEX (title)"
00091 ");",
00092 "CREATE TABLE IF NOT EXISTS videotypes ("
00093 " intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00094 " extension VARCHAR(128) NOT NULL,"
00095 " playcommand VARCHAR(255) NOT NULL,"
00096 " f_ignore BOOL,"
00097 " use_default BOOL"
00098 ");",
00099 ""
00100 };
00101 QString dbver = "";
00102 performActualUpdate(updates, "1000", dbver, OldMythVideoVersionName);
00103
00104 MSqlQuery qQuery(MSqlQuery::InitCon());
00105 qQuery.exec("SELECT * FROM videotypes;");
00106
00107 if (!qQuery.isActive() || qQuery.size() <= 0)
00108 {
00109 const QString updates2[] = {
00110 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default)"
00111 " VALUES ('txt', '', 1, 0);",
00112 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default)"
00113 " VALUES ('log', '', 1, 0);",
00114 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default)"
00115 " VALUES ('mpg', 'Internal', 0, 0);",
00116 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default)"
00117 " VALUES ('avi', '', 0, 1);",
00118 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default)"
00119 " VALUES ('vob', 'Internal', 0, 0);",
00120 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default)"
00121 " VALUES ('mpeg', 'Internal', 0, 0);",
00122 ""
00123 };
00124 dbver = "";
00125 performActualUpdate(updates2, "1000", dbver,
00126 OldMythVideoVersionName);
00127 }
00128 }
00129
00130 bool IsCombinedSchema()
00131 {
00132 QString dbver = gContext->GetSetting(MythVideoVersionName);
00133
00134 return dbver != "";
00135 }
00136
00137 void DoOldVideoDatabaseSchemaUpgrade()
00138 {
00139 if (IsCombinedSchema()) return;
00140
00141 QString dbver = gContext->GetSetting(OldMythVideoVersionName);
00142
00143 if (dbver == lastMythVideoVersion)
00144 return;
00145
00146 if (dbver == "")
00147 {
00148 InitializeVideoDatabase();
00149 dbver = "1000";
00150 }
00151
00152 if (dbver == "1000")
00153 {
00154 const QString updates[] = {
00155 "ALTER TABLE videometadata ADD playcommand VARCHAR(255);",
00156 "ALTER TABLE videometadata ADD INDEX(title);",
00157 "ALTER TABLE videometadata ADD browse BOOL NOT NULL DEFAULT 1;",
00158 ""
00159 };
00160
00161 performActualUpdate(updates, "1001", dbver,
00162 OldMythVideoVersionName);
00163 }
00164
00165 if (dbver == "1001")
00166 {
00167 const QString updates[] = {
00168 "ALTER TABLE videometadata CHANGE childid childid INT NOT NULL DEFAULT -1;",
00169 ""
00170 };
00171
00172 performActualUpdate(updates, "1002", dbver,
00173 OldMythVideoVersionName);
00174 }
00175
00176 if (dbver == "1002")
00177 {
00178 const QString updates[] = {
00179 "ALTER TABLE videometadata CHANGE plot plot TEXT;",
00180 "ALTER TABLE videometadata ADD COLUMN category INT UNSIGNED NOT NULL DEFAULT 0;",
00181 "CREATE TABLE IF NOT EXISTS videocategory ( intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, category VARCHAR(128) NOT NULL );",
00182 "CREATE TABLE IF NOT EXISTS videocountry ( intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, country VARCHAR(128) NOT NULL ); ",
00183 "CREATE TABLE IF NOT EXISTS videometadatacountry ( idvideo INT UNSIGNED NOT NULL, idcountry INT UNSIGNED NOT NULL );",
00184 "CREATE TABLE IF NOT EXISTS videogenre ( intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, genre VARCHAR(128) NOT NULL);",
00185 "CREATE TABLE IF NOT EXISTS videometadatagenre ( idvideo INT UNSIGNED NOT NULL,idgenre INT UNSIGNED NOT NULL );",
00186 ""
00187 };
00188
00189 performActualUpdate(updates, "1003", dbver,
00190 OldMythVideoVersionName);
00191 }
00192
00193
00194 if (dbver == "1003")
00195 {
00196 const QString updates[] = {
00197 "CREATE TABLE IF NOT EXISTS filemarkup"
00198 "("
00199 " filename TEXT NOT NULL,"
00200 " mark BIGINT(20) NOT NULL,"
00201 " offset VARCHAR(32) NULL,"
00202 " type INT NOT NULL"
00203 ");",
00204 ""
00205 };
00206 performActualUpdate(updates, "1004", dbver,
00207 OldMythVideoVersionName);
00208 }
00209
00210 if (dbver == "1004")
00211 {
00212 const QString updates[] = {
00213 "UPDATE keybindings SET keylist = \"[,{,F10\" WHERE action = \"DECPARENT\" AND keylist = \"Left\";",
00214 "UPDATE keybindings SET keylist = \"],},F11\" WHERE action = \"INCPARENT\" AND keylist = \"Right\";",
00215 ""
00216 };
00217 performActualUpdate(updates, "1005", dbver,
00218 OldMythVideoVersionName);
00219 }
00220
00221 if (dbver == "1005")
00222 {
00223 const QString updates[] = {
00224 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default) "
00225 "VALUES ('VIDEO_TS', 'Internal', 0, 0);",
00226 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default) "
00227 "VALUES ('iso', 'Internal', 0, 0);",
00228 ""
00229 };
00230
00231 performActualUpdate(updates, "1006", dbver,
00232 OldMythVideoVersionName);
00233 }
00234
00235 if (dbver == "1006")
00236 {
00237 const QString updates[] = {
00238 "ALTER TABLE videometadatacountry ADD INDEX(idvideo); ",
00239 "ALTER TABLE videometadatacountry ADD INDEX(idcountry);",
00240 "ALTER TABLE videometadatagenre ADD INDEX(idvideo);",
00241 "ALTER TABLE videometadatagenre ADD INDEX(idgenre);",
00242 ""
00243 };
00244
00245 performActualUpdate(updates, "1007", dbver,
00246 OldMythVideoVersionName);
00247 }
00248
00249 if (dbver == "1007")
00250 {
00251 const QString updates[] = {
00252 "INSERT INTO filemarkup (filename, type, mark) SELECT filename,"
00253 " '2', bookmark FROM videobookmarks;",
00254 "DROP TABLE videobookmarks;",
00255 ""
00256 };
00257
00258 performActualUpdate(updates, "1008", dbver,
00259 OldMythVideoVersionName);
00260 }
00261
00262 if (dbver == "1008")
00263 {
00264 QStringList updates;
00265
00266 MSqlQuery query(MSqlQuery::InitCon());
00267 query.exec("SELECT intid FROM videocategory;");
00268
00269 if (query.isActive() && query.size())
00270 {
00271 QString categoryIDs = "'0'";
00272 while (query.next())
00273 {
00274 categoryIDs += ",'" + query.value(0).toString() + "'";
00275 }
00276 updates.append(QString(
00277 "UPDATE videometadata SET category = 0 WHERE category NOT IN (%1);")
00278 .arg(categoryIDs));
00279 }
00280 else
00281 {
00282 updates.append("SELECT 1;");
00283 }
00284
00285 performActualUpdate(updates, "1009", dbver,
00286 OldMythVideoVersionName);
00287 }
00288
00289 if (dbver == "1009")
00290 {
00291 MSqlQuery query(MSqlQuery::InitCon());
00292 query.exec("SELECT extension, playcommand FROM videotypes");
00293
00294 QRegExp extChange("^(img|vob|mpeg|mpg|iso|VIDEO_TS)$", false);
00295 QStringList updates;
00296 if (query.isActive() && query.size())
00297 {
00298 while (query.next())
00299 {
00300 QString extension = query.value(0).toString();
00301 QString playcommand = query.value(1).toString();
00302 if (playcommand != "Internal" &&
00303 extension.find(extChange) == 0)
00304 {
00305 updates.append(QString(
00306 "UPDATE videotypes SET extension = '%1_old' WHERE extension = '%2';")
00307 .arg(extension).arg(extension));
00308 updates.append(QString(
00309 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default) "
00310 "VALUES ('%3', 'Internal', 0, 0);").arg(extension));
00311 }
00312 }
00313 }
00314 updates.append(
00315 "INSERT INTO videotypes (extension, playcommand, f_ignore, use_default) VALUES "
00316 "('img', 'Internal', 0, 0);");
00317
00318 performActualUpdate(updates, "1010", dbver,
00319 OldMythVideoVersionName);
00320 }
00321 }
00322
00323 void InitializeDVDDatabase()
00324 {
00325 VERBOSE(VB_IMPORTANT,
00326 "Inserting MythDVD initial database information.");
00327
00328 MSqlQuery qQuery(MSqlQuery::InitCon());
00329 qQuery.exec("SELECT * FROM dvdinput;");
00330
00331 if (!qQuery.isActive() || qQuery.size() <= 0)
00332 {
00333 const QString updates[] = {
00334 "CREATE TABLE IF NOT EXISTS dvdinput ("
00335 " intid INT UNSIGNED NOT NULL PRIMARY KEY,"
00336 " hsize INT UNSIGNED,"
00337 " vsize INT UNSIGNED,"
00338 " ar_num INT UNSIGNED,"
00339 " ar_denom INT UNSIGNED,"
00340 " fr_code INT UNSIGNED,"
00341 " letterbox BOOL,"
00342 " v_format VARCHAR(16)"
00343 ");",
00344
00345 "INSERT INTO dvdinput"
00346 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00347 " VALUES"
00348 " (1, 720, 480, 16, 9, 1, 1, \"ntsc\");",
00349
00350 "INSERT INTO dvdinput"
00351 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00352 " VALUES"
00353 " (2, 720, 480, 16, 9, 1, 0, \"ntsc\");",
00354
00355 "INSERT INTO dvdinput"
00356 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00357 " VALUES"
00358 " (3, 720, 480, 4, 3, 1, 1, \"ntsc\");",
00359
00360 "INSERT INTO dvdinput"
00361 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00362 " VALUES"
00363 " (4, 720, 480, 4, 3, 1, 0, \"ntsc\");",
00364
00365 "INSERT INTO dvdinput"
00366 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00367 " VALUES"
00368 " (5, 720, 576, 16, 9, 3, 1, \"pal\");",
00369
00370 "INSERT INTO dvdinput"
00371 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00372 " VALUES"
00373 " (6, 720, 576, 16, 9, 3, 0, \"pal\");",
00374
00375 "INSERT INTO dvdinput"
00376 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00377 " VALUES"
00378 " (7, 720, 576, 4, 3, 3, 1, \"pal\");",
00379
00380 "INSERT INTO dvdinput"
00381 " (intid, hsize, vsize, ar_num, ar_denom, fr_code, letterbox, v_format)"
00382 " VALUES"
00383 " (8, 720, 576, 4, 3, 3, 0, \"pal\");",
00384 ""
00385 };
00386 QString dbver = "";
00387 performActualUpdate(updates, "1000", dbver, OldMythDVDVersionName);
00388 }
00389
00390 qQuery.exec("SELECT * FROM dvdtranscode;");
00391 if (!qQuery.isActive() || qQuery.size() <= 0)
00392 {
00393 const QString updates[] = {
00394 "CREATE TABLE IF NOT EXISTS dvdtranscode ("
00395 " intid INT AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00396 " input INT UNSIGNED,"
00397 " name VARCHAR(128) NOT NULL,"
00398 " sync_mode INT UNSIGNED,"
00399 " use_yv12 BOOL,"
00400 " cliptop INT,"
00401 " clipbottom INT,"
00402 " clipleft INT,"
00403 " clipright INT,"
00404 " f_resize_h INT,"
00405 " f_resize_w INT,"
00406 " hq_resize_h INT,"
00407 " hq_resize_w INT,"
00408 " grow_h INT,"
00409 " grow_w INT,"
00410 " clip2top INT,"
00411 " clip2bottom INT,"
00412 " clip2left INT,"
00413 " clip2right INT,"
00414 " codec VARCHAR(128) NOT NULL,"
00415 " codec_param VARCHAR(128),"
00416 " bitrate INT,"
00417 " a_sample_r INT,"
00418 " a_bitrate INT,"
00419 " two_pass BOOL"
00420 ");",
00421
00422 "INSERT INTO dvdtranscode"
00423 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00424 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00425 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00426 " codec, bitrate, two_pass)"
00427 " VALUES"
00428 " (1, \"Good\", 2, 0, 16, 16, 0, 0, 2, 0, 0, 0, 0, 0, 32, 32, 8, 8,"
00429 " \"divx5\", 1618, 0);",
00430
00431 "INSERT INTO dvdtranscode"
00432 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00433 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00434 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00435 " codec, bitrate, two_pass)"
00436 " VALUES"
00437 " (2, \"Excellent\", 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,"
00438 " \"divx5\", 0, 1);",
00439
00440 "INSERT INTO dvdtranscode"
00441 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00442 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00443 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00444 " codec, bitrate, two_pass)"
00445 " VALUES"
00446 " (2, \"Good\", 2, 1, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,"
00447 " \"divx5\", 1618, 0);",
00448
00449 "INSERT INTO dvdtranscode"
00450 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00451 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00452 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00453 " codec, bitrate, two_pass)"
00454 " VALUES"
00455 " (2, \"Medium\", 2, 1, 0, 0, 8, 8, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0,"
00456 " \"divx5\", 1200, 0);",
00457
00458 "INSERT INTO dvdtranscode"
00459 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00460 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00461 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00462 " codec, bitrate, two_pass)"
00463 " VALUES"
00464 " (3, \"Good\", 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 80, 80, 8, 8,"
00465 " \"divx5\", 0, 0);",
00466
00467 "INSERT INTO dvdtranscode"
00468 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00469 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00470 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00471 " codec, bitrate, two_pass)"
00472 " VALUES"
00473 " (4, \"Excellent\", 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,"
00474 " \"divx5\", 0, 1);",
00475
00476 "INSERT INTO dvdtranscode"
00477 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00478 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00479 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00480 " codec, bitrate, two_pass)"
00481 " VALUES"
00482 " (4, \"Good\", 2, 1, 0, 0, 8, 8, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,"
00483 " \"divx5\", 1618, 0);",
00484
00485 "INSERT INTO dvdtranscode"
00486 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00487 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00488 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00489 " codec, bitrate, two_pass)"
00490 " VALUES"
00491 " (5, \"Good\", 1, 1, 16, 16, 0, 0, 5, 0, 0, 0, 0, 0, 40, 40, 8, 8,"
00492 " \"divx5\", 1618, 0);",
00493
00494 "INSERT INTO dvdtranscode"
00495 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00496 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00497 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00498 " codec, bitrate, two_pass)"
00499 " VALUES"
00500 " (6, \"Good\", 1, 1, 0, 0, 16, 16, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,"
00501 " \"divx5\", 1618, 0);",
00502
00503 "INSERT INTO dvdtranscode"
00504 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00505 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00506 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00507 " codec, bitrate, two_pass)"
00508 " VALUES"
00509 " (7, \"Good\", 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 76, 76, 8, 8,"
00510 " \"divx5\", 1618, 0);",
00511
00512 "INSERT INTO dvdtranscode"
00513 " (input, name, sync_mode, use_yv12, cliptop, clipbottom, clipleft, clipright,"
00514 " f_resize_h, f_resize_w, hq_resize_h, hq_resize_w,"
00515 " grow_h, grow_w, clip2top, clip2bottom, clip2left, clip2right,"
00516 " codec, bitrate, two_pass)"
00517 " VALUES"
00518 " (8, \"Good\", 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,"
00519 " \"divx5\", 1618, 0);",
00520 ""
00521 };
00522 QString dbver = "";
00523 performActualUpdate(updates, "1000", dbver, OldMythDVDVersionName);
00524 }
00525 }
00526
00527 void DoOldDVDDatabaseSchemaUpgrage()
00528 {
00529 if (IsCombinedSchema()) return;
00530
00531 QString dbver = gContext->GetSetting(OldMythDVDVersionName);
00532
00533 if (dbver == lastMythDVDDBVersion)
00534 return;
00535
00536 if (dbver == "")
00537 {
00538 InitializeDVDDatabase();
00539 dbver = "1000";
00540 }
00541
00542 if (dbver == "1000")
00543 {
00544 const QString updates[] = {
00545 "UPDATE dvdtranscode SET use_yv12=1 WHERE (intid=1 OR intid=2 OR intid=12 OR intid=13);",
00546 ""
00547 };
00548 performActualUpdate(updates, "1001", dbver, OldMythDVDVersionName);
00549 }
00550
00551 if (dbver == "1001")
00552 {
00553 const QString updates[] = {
00554 "ALTER TABLE dvdtranscode ADD COLUMN tc_param VARCHAR(128);",
00555 ""
00556 };
00557 performActualUpdate(updates, "1002", dbver, OldMythDVDVersionName);
00558 }
00559 }
00560
00561 void DoVideoDatabaseSchemaUpgrade()
00562 {
00563 QString dvdver = gContext->GetSetting(OldMythDVDVersionName);
00564 QString oldmythvideover = gContext->GetSetting(OldMythVideoVersionName);
00565
00566 if (dvdver == lastMythDVDDBVersion &&
00567 oldmythvideover == lastMythVideoVersion)
00568 {
00569 QStringList updates;
00570 updates += QString("DELETE FROM settings WHERE value='%1';")
00571 .arg(OldMythVideoVersionName);
00572 updates += QString("DELETE FROM settings WHERE value='%1';")
00573 .arg(OldMythDVDVersionName);
00574
00575 QString dbver;
00576 performActualUpdate(updates, "1011", dbver, MythVideoVersionName);
00577
00578 VERBOSE(VB_IMPORTANT,
00579 QString("Updated from old MythDVD/MythVideo schema to "
00580 "combined version: %1.").arg(dbver));
00581 }
00582
00583 QString dbver = gContext->GetSetting(MythVideoVersionName);
00584
00585 if (dbver == currentDatabaseVersion)
00586 return;
00587
00588 if (dbver == "1011")
00589 {
00590 const QString updates[] = {
00591 "ALTER TABLE filemarkup MODIFY mark MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, "
00592 "MODIFY offset BIGINT UNSIGNED, "
00593 "MODIFY type TINYINT NOT NULL DEFAULT 0;",
00594 ""
00595 };
00596 performActualUpdate(updates, "1012", dbver, MythVideoVersionName);
00597 }
00598
00599 if (dbver == "1012")
00600 {
00601
00602 const QString setting("Default MythVideo View");
00603 int view = gContext->GetNumSetting(setting, -1);
00604 if (view != -1)
00605 {
00606 switch (view)
00607 {
00608 case 0: view = VideoDialog::DLG_BROWSER; break;
00609 case 2: view = VideoDialog::DLG_TREE; break;
00610 case 1:
00611 default: view = VideoDialog::DLG_GALLERY; break;
00612 }
00613 gContext->SaveSetting(setting, view);
00614 }
00615 performActualUpdate(QStringList(), "1013", dbver,
00616 MythVideoVersionName);
00617 }
00618
00619 if (dbver == "1013")
00620 {
00621 QStringList updates;
00622 updates += "ALTER TABLE filemarkup ADD INDEX (filename(255));";
00623 performActualUpdate(updates, "1014", dbver, MythVideoVersionName);
00624 }
00625
00626 if (dbver == "1014")
00627 {
00628
00629 const QString updates[] = {
00630 "CREATE TABLE videocast ("
00631 "intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00632 "cast VARCHAR(128) NOT NULL);",
00633 "CREATE TABLE videometadatacast ("
00634 "idvideo INT UNSIGNED NOT NULL,"
00635 "idcast INT UNSIGNED NOT NULL);",
00636 ""
00637 };
00638
00639 performActualUpdate(updates, "1015", dbver, MythVideoVersionName);
00640 }
00641
00642 if (dbver == "1015")
00643 {
00644 QStringList updates;
00645 updates +=
00646 "ALTER TABLE videometadata MODIFY inetref VARCHAR(255) NOT NULL;";
00647 performActualUpdate(updates, "1016", dbver, MythVideoVersionName);
00648 }
00649 }
00650 }
00651
00652 void UpgradeVideoDatabaseSchema()
00653 {
00654 if (!IsCombinedSchema())
00655 {
00656 DoOldVideoDatabaseSchemaUpgrade();
00657 DoOldDVDDatabaseSchemaUpgrage();
00658 }
00659
00660 DoVideoDatabaseSchemaUpgrade();
00661 }