Ticket #1699: mfd.patch

File mfd.patch, 12.0 KB (added by jochen, 15 years ago)

MFD Patches for new database style

  • mfd/plugins/mmusic/mmusic.cpp

     
    526526   
    527527    MSqlQuery query(MSqlQuery::InitCon());
    528528   
    529     query.exec("SELECT intid, filename FROM musicmetadata ;");
     529    query.exec("SELECT song_id, filename FROM music_songs ;");
    530530   
    531531    if(query.isActive())
    532532    {
     
    544544
    545545                    ++count;
    546546                    MSqlQuery delete_query(MSqlQuery::InitCon());
    547                     delete_query.prepare("DELETE FROM musicmetadata WHERE intid = ?");
     547                    delete_query.prepare("DELETE FROM music_songs WHERE song_id = ?");
    548548                    delete_query.bindValue(0, query.value(0).toUInt());
    549549                    delete_query.exec();
    550550                    log(QString("removed item %1 (\"%2\") from the database")
     
    556556    }
    557557    else
    558558    {
    559         warning("something wrong with your musicmetadata table");
     559        warning("something wrong with your music_songs table");
    560560    }
    561561   
    562562    if(count > 0)
     
    638638   
    639639    MSqlQuery query(MSqlQuery::InitCon());
    640640   
    641     query.exec("SELECT COUNT(filename) FROM musicmetadata;");
     641    query.exec("SELECT COUNT(filename) FROM music_songs;");
    642642   
    643643    if(!query.isActive())
    644644    {
    645645        if(!sent_musicmetadata_table_warning)
    646646        {
    647             warning("cannot get data from a table called musicmetadata");
     647            warning("cannot get data from a table called music_songs");
    648648            sent_musicmetadata_table_warning = true;
    649649        }
    650650        return false;
     
    977977
    978978    MSqlQuery query(MSqlQuery::InitCon());
    979979
    980     query.prepare("SELECT intid, artist, album, title, genre, "
     980/*    query.prepare("SELECT intid, artist, album, title, genre, "
    981981                  "year, tracknum, length, rating, "
    982982                  "lastplay, playcount, mythdigest, size, date_added, "
    983983                  "date_modified, format, description, comment, "
    984984                  "compilation, composer, disc_count, disc_number, "
    985985                  "track_count, start_time, stop_time, eq_preset, "
    986986                  "relative_volume, sample_rate, bpm "
    987                   "FROM musicmetadata WHERE filename = ? ;");
     987                  "FROM musicmetadata WHERE filename = ? ;");*/
     988    query.prepare("SELECT music_songs.song_id, music_artists.artist_name, "
     989                  "music_albums.album_name, music_songs.name, "
     990                  "music_genres.genre, music_songs.year, "
     991                  "music_songs.track, music_songs.length, "
     992                  "music_songs.rating, music_songs.lastplay, "
     993                  "music_songs.numplays, music_songs.mythdigest,"
     994                  "music_songs.size, music_songs.date_entered, "
     995                  "music_songs.date_modified, music_songs.format, "
     996                  "music_songs.description, music_songs.comment, "
     997                  "music_songs.compilation, music_artists_1.artist_name AS composer, "
     998                  "music_songs.disc_count, music_songs.disc_number, "
     999                  "music_songs.track_count, music_songs.start_time, "
     1000                  "music_songs.stop_time, music_songs.eq_preset, "
     1001                  "music_songs.relative_volume, music_songs.bitrate, "
     1002                  "music_songs.bpm "
     1003                  "FROM (((music_songs INNER JOIN music_albums ON music_songs.album_id = music_albums.album_id) INNER JOIN music_artists ON music_songs.artist_id = music_artists.artist_id) INNER JOIN music_genres ON music_songs.genre_id = music_genres.genre_id) INNER JOIN music_artists AS music_artists_1 ON music_songs.compilationartist_id = music_artists_1.artist_id WHERE FILENAME = ? ;");
    9881004
    9891005    query.bindValue(0, sqlfilename.utf8());
    9901006   
     
    11981214       
    11991215        MSqlQuery query(MSqlQuery::InitCon());
    12001216
    1201         query.prepare("INSERT INTO musicmetadata (filename, mythdigest) "
     1217        query.prepare("INSERT INTO music_songs(filename, mythdigest) "
    12021218                      "values ( ? , ?)");
    12031219
    12041220        query.bindValue(0, sqlfilename.utf8());
     
    12131229            return NULL;
    12141230        }
    12151231       
    1216         query.prepare("SELECT intid FROM musicmetadata "
     1232        query.prepare("SELECT song_id FROM music_songs "
    12171233                               "WHERE mythdigest = ? ;");
    12181234        query.bindValue(0, new_item->getMythDigest());
    12191235        query.exec();
     
    13221338
    13231339    MSqlQuery query(MSqlQuery::InitCon());
    13241340
    1325     query.prepare("UPDATE musicmetadata SET "
    1326                   "title = ? , "
    1327                   "artist = ? , "
    1328                   "album = ? , "
    1329                   "genre = ? , "
     1341    query.prepare("UPDATE music_songs SET "
     1342                  "name = ? , "
     1343                  "artist_id = ? , "
     1344                  "album_id = ? , "
     1345                  "genre_id = ? , "
    13301346                  "year = ? , "
    1331                   "tracknum = ? , "
     1347                  "track = ? , "
    13321348                  "length = ? , "
    13331349                  "rating = ? , "
    13341350                  "lastplay = ? , "
    1335                   "playcount = ? , "
     1351                  "numplays = ? , "
    13361352                  "mythdigest = ? , "
    13371353                  "size = ? , "
    1338                   "date_added = ? , "
     1354                  "date_entered = ? , "
    13391355                  "date_modified = ? , "
    13401356                  "format = ? , "
    13411357                  "description = ? , "
    13421358                  "comment = ? , "
    13431359                  "compilation = ? , "
    1344                   "composer = ? , "
     1360                  "compilationartist_id = ? , "
    13451361                  "disc_count = ? , "
    13461362                  "disc_number = ? , "
    13471363                  "track_count = ? , "
     
    13491365                  "stop_time = ? , "
    13501366                  "eq_preset = ? , "
    13511367                  "relative_volume = ? , "
    1352                   "sample_rate = ? , "
     1368                  "bitrate = ? , "
    13531369                  "bpm = ?  "
    1354                   "WHERE intid = ? ;");
     1370                  "WHERE song_id = ? ;");
    13551371
    13561372    query.bindValue(0,  an_item->getTitle().utf8());
    13571373    query.bindValue(1,  an_item->getArtist().utf8());
     
    14671483
    14681484    MSqlQuery query(MSqlQuery::InitCon());
    14691485
    1470     query.prepare("SELECT name, songlist, playlistid FROM musicplaylist "
     1486    query.prepare("SELECT playlist_name, playlist_songs, playlist_id FROM music_saved_playlists "
    14711487                  "WHERE name != ? "
    1472                   "AND name != ? "
    1473                   "AND hostname = ? ;");
     1488                  "AND name != ? ;");
    14741489       
    14751490    query.bindValue(0, "backup_playlist_storage");
    14761491    query.bindValue(1, "default_playlist_storage");
    1477     query.bindValue(2, hostname);
    14781492       
    14791493    query.exec();
    14801494
     
    16171631   
    16181632    MSqlQuery query(MSqlQuery::InitCon());
    16191633
    1620     query.prepare("UPDATE musicplaylist SET songlist = ?, name = ? WHERE "
    1621                   "playlistid = ? ;");
     1634    query.prepare("UPDATE music_saved_playlists SET playlist_songs = ?, playlist_name = ? WHERE "
     1635                  "playlist_id = ? ;");
    16221636
    16231637    query.bindValue(0, db_song_list_string);
    16241638    query.bindValue(1, a_playlist->getName().utf8());
     
    16651679   
    16661680    MSqlQuery query(MSqlQuery::InitCon());
    16671681
    1668     query.prepare("INSERT INTO musicplaylist (name, hostname, songlist) values (?, ?, ?) ; ");
     1682    query.prepare("INSERT INTO music_saved_playlists (playlist_name, hostname, playlist_songs) values (?, ?, ?) ; ");
    16691683
    16701684    query.bindValue(0, a_playlist->getName().utf8());
    16711685    query.bindValue(1, hostname);
     
    16811695        return;
    16821696    }
    16831697   
    1684     query.prepare("SELECT playlistid FROM musicplaylist WHERE name = ? AND hostname = ? AND songlist = ? ; ");
     1698    query.prepare("SELECT playlist_id FROM music_saved_playlists WHERE playlist_name = ? AND hostname = ? AND playlist_songs = ? ; ");
    16851699
    16861700    query.bindValue(0, a_playlist->getName().utf8());
    16871701    query.bindValue(1, hostname);
     
    17761790
    17771791    MSqlQuery query(MSqlQuery::InitCon());
    17781792
    1779     query.prepare("DELETE FROM musicplaylist WHERE playlistid = ? ; ");
     1793    query.prepare("DELETE FROM music_saved_playlists WHERE playlist_id = ? ; ");
    17801794
    17811795    query.bindValue(0, playlist_database_id);
    17821796       
  • mfd/dbcheck.cpp

     
    99#include "mythtv/mythcontext.h"
    1010#include "mythtv/mythdbcon.h"
    1111
    12 const QString currentDatabaseVersion = "1005";
     12const QString currentDatabaseVersion = "1007";
    1313
    1414static void UpdateDBVersionNumber(const QString &newnumber)
    1515{
     
    323323
    324324        performActualUpdate(updates, "1005", dbver);
    325325    }
     326   
     327   
     328        if (dbver == "1005")
     329            {
     330            const QString updates[] = {
     331"DROP TABLE musicmetadata;",
     332"DROP TABLE musicplaylist;",
     333"CREATE TABLE music_albums (album_id int(11) NOT NULL auto_increment, album_name varchar(255) NOT NULL default '', album_art text NOT NULL, PRIMARY KEY  (album_id));",
     334"CREATE TABLE music_artists (artist_id int(11) NOT NULL auto_increment, artist_name varchar(255) default NULL, PRIMARY KEY  (artist_id));",
     335"CREATE TABLE music_currentsong (song_id int(11) NOT NULL default '0', pl_id int(11) NOT NULL default '0', random tinyint(3) NOT NULL default '0');",
     336"CREATE TABLE music_genres (genre_id int(11) NOT NULL auto_increment, genre varchar(25) NOT NULL default '', PRIMARY KEY  (genre_id));",
     337"CREATE TABLE music_playhistory (play_id int(11) NOT NULL auto_increment, song_id int(11) default NULL, date_played datetime default NULL, PRIMARY KEY  (play_id));",
     338"CREATE TABLE music_playlist (pl_id int(11) NOT NULL auto_increment, song_id int(11) default NULL, PRIMARY KEY  (pl_id));",
     339"CREATE TABLE music_saved_playlists (playlist_id int(11) NOT NULL auto_increment, playlist_name varchar(255) default NULL, playlist_songs text, date_created datetime default NULL, time int(11) default NULL, songcount smallint(8) default NULL, hostname VARCHAR(255), PRIMARY KEY (playlist_id));",
     340"CREATE TABLE music_songs (song_id int(11) NOT NULL auto_increment, artist_id int(11) NOT NULL default '0', compilationartist_id int(11) NOT NULL default '0', album_id int(11) NOT NULL default '0', genre_id int(11) NOT NULL default '0', year smallint(6) NOT NULL default '0', lastplay datetime default NULL, date_entered datetime default NULL, date_modified datetime default NULL, name varchar(255) default NULL, track smallint(6) NOT NULL default '0', length int(11) NOT NULL default '0', size int(11) NOT NULL default '0', bitrate int(11) NOT NULL default '0', type varchar(4) default NULL, numplays int(11) NOT NULL default '0', rating tinyint(4) NOT NULL default '0', filename text, format varchar(4) NOT NULL default '0', compilation tinyint default 0, PRIMARY KEY  (song_id));",
     341"CREATE TABLE music_stats (num_artists smallint(5) unsigned NOT NULL default '0', num_albums smallint(5) unsigned NOT NULL default '0', num_songs mediumint(8) unsigned NOT NULL default '0', num_genres tinyint(3) unsigned NOT NULL default '0', total_time varchar(12) NOT NULL default '0', total_size varchar(10) NOT NULL default '0');",
     342"RENAME TABLE smartplaylist TO music_smartplaylist;",
     343"RENAME TABLE smartplaylistitem TO music_smartplaylistitem;",
     344"RENAME TABLE smartplaylistcategory TO music_smartplaylistcategory;",
     345""
     346};
     347        performActualUpdate(updates, "1006", dbver);
     348    }
     349
     350        if (dbver == "1006")
     351            {
     352            //Database Updates for use in the MFD
     353            const QString updates[] = {
     354"ALTER TABLE music_songs ADD mythdigest      VARCHAR(255);",
     355"ALTER TABLE music_songs ADD description     VARCHAR(255);",
     356"ALTER TABLE music_songs ADD comment         VARCHAR(255);",
     357"ALTER TABLE music_songs ADD disc_count      SMALLINT UNSIGNED DEFAULT 0;",
     358"ALTER TABLE music_songs ADD disc_number     SMALLINT UNSIGNED DEFAULT 0;",
     359"ALTER TABLE music_songs ADD track_count     SMALLINT UNSIGNED DEFAULT 0;",
     360"ALTER TABLE music_songs ADD start_time      INT UNSIGNED DEFAULT 0;",
     361"ALTER TABLE music_songs ADD stop_time       INT UNSIGNED;",
     362"ALTER TABLE music_songs ADD eq_preset       VARCHAR(255);",
     363"ALTER TABLE music_songs ADD relative_volume TINYINT DEFAULT 0;",
     364"ALTER TABLE music_songs ADD bpm             SMALLINT UNSIGNED;",
     365"ALTER TABLE music_songs ADD INDEX (mythdigest);",
     366""
     367};
     368        performActualUpdate(updates, "1007", dbver);
     369    }
     370
    326371}
    327372