00001 #include <qstring.h>
00002 #include <qdir.h>
00003
00004 #include <iostream>
00005 using namespace std;
00006
00007 #include "dbcheck.h"
00008 #include "metadata.h"
00009 #include "mythtv/mythcontext.h"
00010 #include "mythtv/mythdbcon.h"
00011
00012 const QString currentDatabaseVersion = "1013";
00013
00014 static bool UpdateDBVersionNumber(const QString &newnumber)
00015 {
00016
00017 if (!gContext->SaveSettingOnHost("MusicDBSchemaVer",newnumber,NULL))
00018 {
00019 VERBOSE(VB_IMPORTANT, QString("DB Error (Setting new DB version number): %1\n")
00020 .arg(newnumber));
00021
00022 return false;
00023 }
00024
00025 return true;
00026 }
00027
00028 static bool performActualUpdate(const QString updates[], QString version,
00029 QString &dbver)
00030 {
00031 MSqlQuery query(MSqlQuery::InitCon());
00032
00033 VERBOSE(VB_IMPORTANT, QString("Upgrading to MythMusic schema version ") +
00034 version);
00035
00036 int counter = 0;
00037 QString thequery = updates[counter];
00038
00039 while (thequery != "")
00040 {
00041 query.prepare(thequery);
00042 query.exec();
00043
00044 if (query.lastError().type() != QSqlError::None)
00045 {
00046 QString msg =
00047 QString("DB Error (Performing database upgrade): \n"
00048 "Query was: %1 \nError was: %2 \nnew version: %3")
00049 .arg(thequery)
00050 .arg(MythContext::DBErrorMessage(query.lastError()))
00051 .arg(version);
00052 VERBOSE(VB_IMPORTANT, msg);
00053 return false;
00054 }
00055
00056 counter++;
00057 thequery = updates[counter];
00058 }
00059
00060 if (!UpdateDBVersionNumber(version))
00061 return false;
00062
00063 dbver = version;
00064 return true;
00065 }
00066
00067 bool UpgradeMusicDatabaseSchema(void)
00068 {
00069 QString dbver = gContext->GetSetting("MusicDBSchemaVer");
00070
00071 if (dbver == currentDatabaseVersion)
00072 return true;
00073
00074 if (dbver == "")
00075 {
00076 VERBOSE(VB_IMPORTANT, "Inserting MythMusic initial database information.");
00077
00078 const QString updates[] = {
00079 "CREATE TABLE IF NOT EXISTS musicmetadata ("
00080 " intid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00081 " artist VARCHAR(128) NOT NULL,"
00082 " album VARCHAR(128) NOT NULL,"
00083 " title VARCHAR(128) NOT NULL,"
00084 " genre VARCHAR(128) NOT NULL,"
00085 " year INT UNSIGNED NOT NULL,"
00086 " tracknum INT UNSIGNED NOT NULL,"
00087 " length INT UNSIGNED NOT NULL,"
00088 " filename TEXT NOT NULL,"
00089 " rating INT UNSIGNED NOT NULL DEFAULT 5,"
00090 " lastplay TIMESTAMP NOT NULL,"
00091 " playcount INT UNSIGNED NOT NULL DEFAULT 0,"
00092 " INDEX (artist),"
00093 " INDEX (album),"
00094 " INDEX (title),"
00095 " INDEX (genre)"
00096 ");",
00097 "CREATE TABLE IF NOT EXISTS musicplaylist ("
00098 " playlistid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00099 " name VARCHAR(128) NOT NULL,"
00100 " hostname VARCHAR(255),"
00101 " songlist TEXT NOT NULL"
00102 ");",
00103 ""
00104 };
00105 if (!performActualUpdate(updates, "1000", dbver))
00106 return false;
00107 }
00108
00109 if (dbver == "1000")
00110 {
00111 QString startdir = gContext->GetSetting("MusicLocation");
00112 startdir = QDir::cleanDirPath(startdir);
00113 if (!startdir.endsWith("/"))
00114 startdir += "/";
00115
00116 MSqlQuery query(MSqlQuery::InitCon());
00117
00118 query.exec("SELECT filename, intid FROM musicmetadata WHERE "
00119 "filename NOT LIKE ('%://%');");
00120
00121 if (query.isActive() && query.size() > 0)
00122 {
00123 int i = 0;
00124 QString intid, name, newname;
00125
00126 MSqlQuery modify(MSqlQuery::InitCon());
00127 while (query.next())
00128 {
00129 name = query.value(0).toString();
00130 newname = name;
00131 intid = query.value(1).toString();
00132
00133 if (newname.startsWith(startdir))
00134 {
00135 newname.remove(0, startdir.length());
00136 modify.exec(QString("UPDATE musicmetadata SET "
00137 "filename = \"%1\" "
00138 "WHERE filename = \"%2\" AND intid = %3;")
00139 .arg(newname).arg(name).arg(intid));
00140 if (modify.isActive())
00141 i += modify.numRowsAffected();
00142 }
00143 }
00144 VERBOSE(VB_IMPORTANT, QString("Modified %1 entries for db schema 1001").arg(i));
00145 }
00146
00147 const QString updates[] = {
00148 ""
00149 };
00150 if (!performActualUpdate(updates, "1001", dbver))
00151 return false;
00152 }
00153
00154 if (dbver == "1001")
00155 {
00156 const QString updates[] = {
00157 "ALTER TABLE musicmetadata ADD mythdigest VARCHAR(255);",
00158 "ALTER TABLE musicmetadata ADD size BIGINT UNSIGNED;",
00159 "ALTER TABLE musicmetadata ADD date_added DATETIME;",
00160 "ALTER TABLE musicmetadata ADD date_modified DATETIME;",
00161 "ALTER TABLE musicmetadata ADD format VARCHAR(4);",
00162 "ALTER TABLE musicmetadata ADD description VARCHAR(255);",
00163 "ALTER TABLE musicmetadata ADD comment VARCHAR(255);",
00164 "ALTER TABLE musicmetadata ADD compilation TINYINT DEFAULT 0;",
00165 "ALTER TABLE musicmetadata ADD composer VARCHAR(255);",
00166 "ALTER TABLE musicmetadata ADD disc_count SMALLINT UNSIGNED DEFAULT 0;",
00167 "ALTER TABLE musicmetadata ADD disc_number SMALLINT UNSIGNED DEFAULT 0;",
00168 "ALTER TABLE musicmetadata ADD track_count SMALLINT UNSIGNED DEFAULT 0;",
00169 "ALTER TABLE musicmetadata ADD start_time INT UNSIGNED DEFAULT 0;",
00170 "ALTER TABLE musicmetadata ADD stop_time INT UNSIGNED;",
00171 "ALTER TABLE musicmetadata ADD eq_preset VARCHAR(255);",
00172 "ALTER TABLE musicmetadata ADD relative_volume TINYINT DEFAULT 0;",
00173 "ALTER TABLE musicmetadata ADD sample_rate INT UNSIGNED;",
00174 "ALTER TABLE musicmetadata ADD bpm SMALLINT UNSIGNED;",
00175 "ALTER TABLE musicmetadata ADD INDEX (mythdigest);",
00176 ""
00177 };
00178 if (!performActualUpdate(updates, "1002", dbver))
00179 return false;
00180 }
00181
00182 if (dbver == "1002")
00183 {
00184 VERBOSE(VB_IMPORTANT, "Updating music metadata to be UTF-8 in the database");
00185
00186 MSqlQuery query(MSqlQuery::InitCon());
00187 query.prepare("SELECT intid, artist, album, title, genre, "
00188 "filename FROM musicmetadata ORDER BY intid;");
00189
00190 if (query.exec() && query.isActive() && query.size() > 0)
00191 {
00192 while (query.next())
00193 {
00194 int id = query.value(0).toInt();
00195 QString artist = query.value(1).toString();
00196 QString album = query.value(2).toString();
00197 QString title = query.value(3).toString();
00198 QString genre = query.value(4).toString();
00199 QString filename = query.value(5).toString();
00200
00201 MSqlQuery subquery(MSqlQuery::InitCon());
00202 subquery.prepare("UPDATE musicmetadata SET "
00203 "artist = :ARTIST, album = :ALBUM, "
00204 "title = :TITLE, genre = :GENRE, "
00205 "filename = :FILENAME "
00206 "WHERE intid = :ID;");
00207 subquery.bindValue(":ARTIST", artist.utf8());
00208 subquery.bindValue(":ALBUM", album.utf8());
00209 subquery.bindValue(":TITLE", title.utf8());
00210 subquery.bindValue(":GENRE", genre.utf8());
00211 subquery.bindValue(":FILENAME", filename.utf8());
00212 subquery.bindValue(":ID", id);
00213
00214 if (!subquery.exec() || !subquery.isActive())
00215 MythContext::DBError("music utf8 update", subquery);
00216 }
00217 }
00218
00219 query.prepare("SELECT playlistid, name FROM musicplaylist "
00220 "ORDER BY playlistid;");
00221
00222 if (query.exec() && query.isActive() && query.size() > 0)
00223 {
00224 while (query.next())
00225 {
00226 int id = query.value(0).toInt();
00227 QString name = query.value(1).toString();
00228
00229 MSqlQuery subquery(MSqlQuery::InitCon());
00230 subquery.prepare("UPDATE musicplaylist SET "
00231 "name = :NAME WHERE playlistid = :ID ;");
00232 subquery.bindValue(":NAME", name.utf8());
00233 subquery.bindValue(":ID", id);
00234
00235 if (!subquery.exec() || !subquery.isActive())
00236 MythContext::DBError("music playlist utf8 update", subquery);
00237 }
00238 }
00239
00240 VERBOSE(VB_IMPORTANT, "Done updating music metadata to UTF-8");
00241
00242 const QString updates[] = {
00243 ""
00244 };
00245 if (!performActualUpdate(updates, "1003", dbver))
00246 return false;
00247 }
00248
00249 if (dbver == "1003")
00250 {
00251 const QString updates[] = {
00252 "DROP TABLE IF EXISTS smartplaylistcategory;",
00253 "CREATE TABLE smartplaylistcategory ("
00254 " categoryid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00255 " name VARCHAR(128) NOT NULL,"
00256 " INDEX (name)"
00257 ");",
00258
00259 "INSERT INTO smartplaylistcategory SET categoryid = 1, "
00260 " name = \"Decades\";",
00261 "INSERT INTO smartplaylistcategory SET categoryid = 2, "
00262 " name = \"Favourite Tracks\";",
00263 "INSERT INTO smartplaylistcategory SET categoryid = 3, "
00264 " name = \"New Tracks\";",
00265
00266 "DROP TABLE IF EXISTS smartplaylist;",
00267 "CREATE TABLE smartplaylist ("
00268 " smartplaylistid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00269 " name VARCHAR(128) NOT NULL,"
00270 " categoryid INT UNSIGNED NOT NULL,"
00271 " matchtype SET('All', 'Any') NOT NULL DEFAULT 'All',"
00272 " orderby VARCHAR(128) NOT NULL DEFAULT '',"
00273 " limitto INT UNSIGNED NOT NULL DEFAULT 0,"
00274 " INDEX (name),"
00275 " INDEX (categoryid)"
00276 ");",
00277 "DROP TABLE IF EXISTS smartplaylistitem;",
00278 "CREATE TABLE smartplaylistitem ("
00279 " smartplaylistitemid INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,"
00280 " smartplaylistid INT UNSIGNED NOT NULL,"
00281 " field VARCHAR(50) NOT NULL,"
00282 " operator VARCHAR(20) NOT NULL,"
00283 " value1 VARCHAR(255) NOT NULL,"
00284 " value2 VARCHAR(255) NOT NULL,"
00285 " INDEX (smartplaylistid)"
00286 ");",
00287 "INSERT INTO smartplaylist SET smartplaylistid = 1, name = \"1960's\", "
00288 " categoryid = 1, matchtype = \"All\", orderby = \"Artist (A)\","
00289 " limitto = 0;",
00290 "INSERT INTO smartplaylistitem SET smartplaylistid = 1, field = \"Year\","
00291 " operator = \"is between\", value1 = \"1960\", value2 = \"1969\";",
00292
00293 "INSERT INTO smartplaylist SET smartplaylistid = 2, name = \"1970's\", "
00294 " categoryid = 1, matchtype = \"All\", orderby = \"Artist (A)\","
00295 " limitto = 0;",
00296 "INSERT INTO smartplaylistitem SET smartplaylistid = 2, field = \"Year\","
00297 " operator = \"is between\", value1 = \"1970\", value2 = \"1979\";",
00298
00299 "INSERT INTO smartplaylist SET smartplaylistid = 3, name = \"1980's\", "
00300 " categoryid = 1, matchtype = \"All\", orderby = \"Artist (A)\","
00301 " limitto = 0;",
00302 "INSERT INTO smartplaylistitem SET smartplaylistid = 3, field = \"Year\","
00303 " operator = \"is between\", value1 = \"1980\", value2 = \"1989\";",
00304
00305 "INSERT INTO smartplaylist SET smartplaylistid = 4, name = \"1990's\", "
00306 " categoryid = 1, matchtype = \"All\", orderby = \"Artist (A)\","
00307 " limitto = 0;",
00308 "INSERT INTO smartplaylistitem SET smartplaylistid = 4, field = \"Year\","
00309 " operator = \"is between\", value1 = \"1990\", value2 = \"1999\";",
00310
00311 "INSERT INTO smartplaylist SET smartplaylistid = 5, name = \"2000's\", "
00312 " categoryid = 1, matchtype = \"All\", orderby = \"Artist (A)\","
00313 " limitto = 0;",
00314 "INSERT INTO smartplaylistitem SET smartplaylistid = 5, field = \"Year\","
00315 " operator = \"is between\", value1 = \"2000\", value2 = \"2009\";",
00316
00317 "INSERT INTO smartplaylist SET smartplaylistid = 6, name = \"Favorite Tracks\", "
00318 " categoryid = 2, matchtype = \"All\","
00319 " orderby = \"Artist (A), Album (A)\", limitto = 0;",
00320 "INSERT INTO smartplaylistitem SET smartplaylistid = 6, field = \"Rating\","
00321 " operator = \"is greater than\", value1 = \"7\", value2 = \"0\";",
00322
00323 "INSERT INTO smartplaylist SET smartplaylistid = 7, name = \"100 Most Played Tracks\", "
00324 " categoryid = 2, matchtype = \"All\", orderby = \"Play Count (D)\","
00325 " limitto = 100;",
00326 "INSERT INTO smartplaylistitem SET smartplaylistid = 7, field = \"Play Count\","
00327 " operator = \"is greater than\", value1 = \"0\", value2 = \"0\";",
00328
00329 "INSERT INTO smartplaylist SET smartplaylistid = 8, name = \"Never Played Tracks\", "
00330 " categoryid = 3, matchtype = \"All\", orderby = \"Artist (A), Album (A)\","
00331 " limitto = 0;",
00332 "INSERT INTO smartplaylistitem SET smartplaylistid = 8, field = \"Play Count\","
00333 " operator = \"is equal to\", value1 = \"0\", value2 = \"0\";",
00334
00335 ""
00336 };
00337
00338 if (!performActualUpdate(updates, "1004", dbver))
00339 return false;
00340 }
00341
00342 if (dbver == "1004")
00343 {
00344 const QString updates[] = {
00345 "ALTER TABLE musicmetadata ADD compilation_artist VARCHAR(128) NOT NULL AFTER artist;",
00346 "ALTER TABLE musicmetadata ADD INDEX (compilation_artist);",
00347 ""
00348 };
00349
00350 if (!performActualUpdate(updates, "1005", dbver))
00351 return false;
00352 }
00353
00354
00355 if (dbver == "1005")
00356 {
00357 const QString updates[] = {
00358 "CREATE TABLE music_albums ("
00359 " album_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
00360 " artist_id int(11) unsigned NOT NULL default '0',"
00361 " album_name varchar(255) NOT NULL default '',"
00362 " year smallint(6) NOT NULL default '0',"
00363 " compilation tinyint(1) unsigned NOT NULL default '0',"
00364 " INDEX idx_album_name(album_name)"
00365 ");",
00366 "CREATE TABLE music_artists ("
00367 " artist_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
00368 " artist_name varchar(255) NOT NULL default '',"
00369 " INDEX idx_artist_name(artist_name)"
00370 ");",
00371 "CREATE TABLE music_genres ("
00372 " genre_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
00373 " genre varchar(25) NOT NULL default '',"
00374 " INDEX idx_genre(genre)"
00375 ");",
00376 "CREATE TABLE music_playlists ("
00377 " playlist_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
00378 " playlist_name varchar(255) NOT NULL default '',"
00379 " playlist_songs text NOT NULL default '',"
00380 " last_accessed timestamp NOT NULL,"
00381 " length int(11) unsigned NOT NULL default '0',"
00382 " songcount smallint(8) unsigned NOT NULL default '0',"
00383 " hostname VARCHAR(255) NOT NULL default ''"
00384 ");",
00385 "CREATE TABLE music_songs ("
00386 " song_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
00387 " filename text NOT NULL default '',"
00388 " name varchar(255) NOT NULL default '',"
00389 " track smallint(6) unsigned NOT NULL default '0',"
00390 " artist_id int(11) unsigned NOT NULL default '0',"
00391 " album_id int(11) unsigned NOT NULL default '0',"
00392 " genre_id int(11) unsigned NOT NULL default '0',"
00393 " year smallint(6) NOT NULL default '0',"
00394 " length int(11) unsigned NOT NULL default '0',"
00395 " numplays int(11) unsigned NOT NULL default '0',"
00396 " rating tinyint(4) unsigned NOT NULL default '0',"
00397 " lastplay timestamp NOT NULL,"
00398 " date_entered datetime default NULL,"
00399 " date_modified datetime default NULL,"
00400 " format varchar(4) NOT NULL default '0',"
00401 " mythdigest VARCHAR(255),"
00402 " size BIGINT(20) unsigned,"
00403 " description VARCHAR(255),"
00404 " comment VARCHAR(255),"
00405 " disc_count SMALLINT(5) UNSIGNED DEFAULT '0',"
00406 " disc_number SMALLINT(5) UNSIGNED DEFAULT '0',"
00407 " track_count SMALLINT(5) UNSIGNED DEFAULT '0',"
00408 " start_time INT(10) UNSIGNED DEFAULT '0',"
00409 " stop_time INT(10) UNSIGNED,"
00410 " eq_preset VARCHAR(255),"
00411 " relative_volume TINYINT DEFAULT '0',"
00412 " sample_rate INT(10) UNSIGNED DEFAULT '0',"
00413 " bitrate INT(10) UNSIGNED DEFAULT '0',"
00414 " bpm SMALLINT(5) UNSIGNED,"
00415 " INDEX idx_name(name),"
00416 " INDEX idx_mythdigest(mythdigest)"
00417 ");",
00418 "CREATE TABLE music_stats ("
00419 " num_artists smallint(5) unsigned NOT NULL default '0',"
00420 " num_albums smallint(5) unsigned NOT NULL default '0',"
00421 " num_songs mediumint(8) unsigned NOT NULL default '0',"
00422 " num_genres tinyint(3) unsigned NOT NULL default '0',"
00423 " total_time varchar(12) NOT NULL default '0',"
00424 " total_size varchar(10) NOT NULL default '0'"
00425 ");",
00426 "RENAME TABLE smartplaylist TO music_smartplaylists;",
00427 "RENAME TABLE smartplaylistitem TO music_smartplaylist_items;",
00428 "RENAME TABLE smartplaylistcategory TO music_smartplaylist_categories;",
00429
00430 "CREATE TEMPORARY TABLE tmp_artists"
00431 " SELECT DISTINCT artist FROM musicmetadata;",
00432 "INSERT INTO tmp_artists"
00433 " SELECT DISTINCT compilation_artist"
00434 " FROM musicmetadata"
00435 " WHERE compilation_artist<>artist;",
00436 "INSERT INTO music_artists (artist_name) SELECT DISTINCT artist FROM tmp_artists;",
00437 "INSERT INTO music_albums (artist_id, album_name, year, compilation) "
00438 " SELECT artist_id, album, ROUND(AVG(year)) AS year, IF(SUM(compilation),1,0) AS compilation"
00439 " FROM musicmetadata"
00440 " LEFT JOIN music_artists ON compilation_artist=artist_name"
00441 " GROUP BY artist_id, album;",
00442 "INSERT INTO music_genres (genre) SELECT DISTINCT genre FROM musicmetadata;",
00443 "INSERT INTO music_songs "
00444 " (song_id, artist_id, album_id, genre_id, year, lastplay,"
00445 " date_entered, date_modified, name, track, length, size, numplays,"
00446 " rating, filename)"
00447 " SELECT intid, ma.artist_id, mb.album_id, mg.genre_id, mmd.year, lastplay,"
00448 " date_added, date_modified, title, tracknum, length, IFNULL(size,0), playcount,"
00449 " rating, filename"
00450 " FROM musicmetadata AS mmd"
00451 " LEFT JOIN music_artists AS ma ON mmd.artist=ma.artist_name"
00452 " LEFT JOIN music_artists AS mc ON mmd.compilation_artist=mc.artist_name"
00453 " LEFT JOIN music_albums AS mb ON mmd.album=mb.album_name AND mc.artist_id=mb.artist_id"
00454 " LEFT JOIN music_genres AS mg ON mmd.genre=mg.genre;",
00455 "INSERT INTO music_playlists"
00456 " (playlist_id,playlist_name,playlist_songs,hostname)"
00457 " SELECT playlistid, name, songlist, hostname"
00458 " FROM musicplaylist;",
00459
00460 "UPDATE music_playlists"
00461 " SET hostname=''"
00462 " WHERE playlist_name<>'default_playlist_storage'"
00463 " AND playlist_name<>'backup_playlist_storage';",
00464 ""
00465 };
00466 if (!performActualUpdate(updates, "1006", dbver))
00467 return false;
00468 }
00469
00470 if (dbver == "1006")
00471 {
00472 const QString updates[] = {
00473 "ALTER TABLE music_genres MODIFY genre VARCHAR(255) NOT NULL default '';",
00474 ""
00475 };
00476 if (!performActualUpdate(updates, "1007", dbver))
00477 return false;
00478 }
00479
00480 if (dbver == "1007")
00481 {
00482 const QString updates[] = {
00483 "ALTER TABLE music_songs MODIFY lastplay DATETIME DEFAULT NULL;",
00484 "CREATE TABLE music_directories (directory_id int(20) NOT NULL AUTO_INCREMENT "
00485 "PRIMARY KEY, path TEXT NOT NULL DEFAULT '', "
00486 "parent_id INT(20) NOT NULL DEFAULT '0') ;",
00487 "INSERT IGNORE INTO music_directories (path) SELECT DISTINCT"
00488 " SUBSTRING(filename FROM 1 FOR INSTR(filename, "
00489 "SUBSTRING_INDEX(filename, '/', -1))-2) FROM music_songs;",
00490 "CREATE TEMPORARY TABLE tmp_songs SELECT music_songs.*, directory_id "
00491 "FROM music_songs, music_directories WHERE "
00492 "music_directories.path=SUBSTRING(filename FROM 1 FOR "
00493 "INSTR(filename, SUBSTRING_INDEX(filename, '/', -1))-2);",
00494 "UPDATE tmp_songs SET filename=SUBSTRING_INDEX(filename, '/', -1);",
00495 "DELETE FROM music_songs;",
00496 "ALTER TABLE music_songs ADD COLUMN directory_id int(20) NOT NULL DEFAULT '0';",
00497 "INSERT INTO music_songs SELECT * FROM tmp_songs;",
00498 "ALTER TABLE music_songs ADD INDEX (directory_id);",
00499 ""
00500 };
00501
00502 if (!performActualUpdate(updates, "1008", dbver))
00503 return false;
00504 }
00505
00506 if (dbver == "1008")
00507 {
00508 const QString updates[] = {
00509 "CREATE TABLE music_albumart (albumart_id int(20) NOT NULL AUTO_INCREMENT "
00510 "PRIMARY KEY, filename VARCHAR(255) NOT NULL DEFAULT '', directory_id INT(20) "
00511 "NOT NULL DEFAULT '0');",
00512 ""
00513 };
00514
00515 if (!performActualUpdate(updates, "1009", dbver))
00516 return false;
00517 }
00518
00519 if (dbver == "1009")
00520 {
00521 const QString updates[] = {
00522 "ALTER TABLE music_albumart ADD COLUMN imagetype tinyint(3) NOT NULL DEFAULT '0';",
00523 ""
00524 };
00525
00526 if (!performActualUpdate(updates, "1010", dbver))
00527 return false;
00528
00529
00530
00531
00532 VERBOSE(VB_IMPORTANT, "Updating music_albumart image types");
00533
00534 MSqlQuery query(MSqlQuery::InitCon());
00535 query.prepare("SELECT albumart_id, filename, directory_id, imagetype FROM music_albumart;");
00536
00537 if (query.exec())
00538 {
00539 while (query.next())
00540 {
00541 int id = query.value(0).toInt();
00542 QString filename = query.value(1).toString();
00543 int directoryID = query.value(2).toInt();
00544 int type = IT_UNKNOWN;
00545 MSqlQuery subquery(MSqlQuery::InitCon());
00546
00547
00548 type = AlbumArtImages::guessImageType(filename);
00549
00550
00551
00552 if (type == IT_UNKNOWN)
00553 {
00554 subquery.prepare("SELECT count(directory_id) FROM music_albumart "
00555 "WHERE directory_id = :DIR;");
00556 subquery.bindValue(":DIR", directoryID);
00557 if (!subquery.exec() || !subquery.isActive())
00558 MythContext::DBError("album art image count", subquery);
00559 subquery.first();
00560 if (query.value(0).toInt() == 1)
00561 type = IT_FRONTCOVER;
00562 }
00563
00564
00565 subquery.prepare("UPDATE music_albumart "
00566 "SET imagetype = :TYPE "
00567 "WHERE albumart_id = :ID;");
00568 subquery.bindValue(":TYPE", type);
00569 subquery.bindValue(":ID", id);
00570 if (!subquery.exec() || !subquery.isActive())
00571 MythContext::DBError("album art image type update", subquery);
00572 }
00573 }
00574 }
00575
00576 if (dbver == "1010")
00577 {
00578 const QString updates[] = {"", ""};
00579
00580
00581 QString setting = gContext->GetSetting("VisualMode");
00582 setting = setting.simplifyWhiteSpace();
00583 setting = setting.replace(' ', ";");
00584 gContext->SaveSetting("VisualMode", setting);
00585
00586 if (!performActualUpdate(updates, "1011", dbver))
00587 return false;
00588
00589 }
00590
00591 if (dbver == "1011")
00592 {
00593 const QString updates[] = {
00594 "ALTER TABLE music_albumart ADD COLUMN song_id int(11) NOT NULL DEFAULT '0', ADD COLUMN embedded TINYINT(1) NOT NULL DEFAULT '0';",
00595 ""
00596 };
00597
00598 if (!performActualUpdate(updates, "1012", dbver))
00599 return false;
00600
00601 }
00602
00603 if (dbver == "1012")
00604 {
00605 const QString updates[] = {
00606 "ALTER TABLE music_songs ADD INDEX album_id (album_id);",
00607 "ALTER TABLE music_songs ADD INDEX genre_id (genre_id);",
00608 "ALTER TABLE music_songs ADD INDEX artist_id (artist_id);",
00609 ""
00610 };
00611
00612 if (!performActualUpdate(updates, "1013", dbver))
00613 return false;
00614
00615 }
00616
00617
00618
00619
00620
00621 return true;
00622 }