Ticket #1919: mythmusic_schema_mythmusic.diff

File mythmusic_schema_mythmusic.diff, 74.3 KB (added by Colin Guthrie <mythtv@…>, 13 years ago)

v2 Myth Music Only Changes

  • mythmusic/mythmusic/playbackbox.cpp

     
    541541        return;
    542542
    543543   closePlaylistPopup();
    544    updatePlaylistFromQuickPlaylist("ORDER BY artist, album, tracknum");
     544   updatePlaylistFromQuickPlaylist("ORDER BY artist_name, album_name, track");
    545545}
    546546
    547547void PlaybackBoxMusic::fromCD()
     
    597597        return;
    598598
    599599    QString value = formattedFieldValue(curMeta->Artist().utf8());
    600     QString whereClause = "WHERE artist = " + value +
    601                           " ORDER BY album, tracknum";
     600    QString whereClause = "WHERE artist_name = " + value +
     601                          " ORDER BY album_name, track";
    602602
    603603    closePlaylistPopup();
    604604    updatePlaylistFromQuickPlaylist(whereClause);
     
    610610        return;
    611611
    612612    QString value = formattedFieldValue(curMeta->Album().utf8());
    613     QString whereClause = "WHERE album = " + value +
    614                           " ORDER BY tracknum";
     613    QString whereClause = "WHERE album_name = " + value +
     614                          " ORDER BY track";
    615615    closePlaylistPopup();
    616616    updatePlaylistFromQuickPlaylist(whereClause);
    617617}
     
    623623
    624624    QString value = formattedFieldValue(curMeta->Genre().utf8());
    625625    QString whereClause = "WHERE genre = " + value +
    626                           " ORDER BY artist, album, tracknum";   
     626                          " ORDER BY artist_name, album_name, track";   
    627627    closePlaylistPopup();
    628628    updatePlaylistFromQuickPlaylist(whereClause);
    629629}
     
    635635
    636636    QString value = formattedFieldValue(curMeta->Year());
    637637    QString whereClause = "WHERE year = " + value +
    638                           " ORDER BY artist, album, tracknum";
     638                          " ORDER BY artist_name, album_name, track";
    639639    closePlaylistPopup();
    640640    updatePlaylistFromQuickPlaylist(whereClause);
    641641}
  • mythmusic/mythmusic/search.cpp

     
    6666
    6767void SearchDialog::runQuery(QString searchText)
    6868{
    69     // This method will perform a search in the 'musicmetadata' table and fill
     69    // This method will perform a search in the various music_* tables and fill
    7070    // the 'listbox' widget with the results.
    7171    // The following columns are searched: filename, artist, album, title.
    7272    // To facilitate usage with a remote, two search modes exist and
     
    103103
    104104    MSqlQuery query(MSqlQuery::InitCon());
    105105
    106     QString queryString("SELECT filename, artist, album, title, intid "
    107                         "FROM musicmetadata ");
     106    QString queryString("SELECT filename, artist_name, album_name, name, song_id "
     107                        "FROM music_songs "
     108                        "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     109                        "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id ");     
    108110
    109111    QStringList list = QStringList::split(QRegExp("[>,]"), searchText);
    110112    whereClause = "";
     
    117119                 QString stxt = list[i];
    118120                 whereClause += (i) ? " AND ( " : "WHERE (";
    119121                 whereClause +=
    120                     "filename LIKE '%" + stxt + "%' OR "
    121                     "artist  LIKE '%" + stxt + "%' OR "
    122                     "album    LIKE '%" + stxt + "%' OR "
    123                     "title    LIKE '%" + stxt + "%')";
     122                    "filename    LIKE '%" + stxt + "%' OR "
     123                    "artist_name LIKE '%" + stxt + "%' OR "
     124                    "album_name  LIKE '%" + stxt + "%' OR "
     125                    "name    LIKE '%" + stxt + "%')";
    124126             }
    125127             VERBOSE(VB_GENERAL, QString("alpha whereClause " + whereClause ));
    126128        }
     
    131133                QString stxt = list[i].stripWhiteSpace();
    132134                whereClause += (i) ? " AND ( " : "WHERE (";
    133135                whereClause +=
    134                     "filename REGEXP '" + stxt + "' OR "
    135                     "artist  REGEXP '" + stxt + "' OR "
    136                     "album    REGEXP '" + stxt + "' OR "
    137                     "title    REGEXP '" + stxt + "')";
     136                    "filename    REGEXP '" + stxt + "' OR "
     137                    "artist_name REGEXP '" + stxt + "' OR "
     138                    "album_name  REGEXP '" + stxt + "' OR "
     139                    "name        REGEXP '" + stxt + "')";
    138140            }
    139141            VERBOSE(VB_GENERAL,QString("numeric whereClause " + whereClause ));
    140142        }
    141143    }
    142144
    143145    queryString += whereClause;
    144     queryString += " ORDER BY artist, album, title, intid, filename ";
     146    queryString += " ORDER BY artist_name, album_name, name, song_id, filename ";
    145147
    146148    query.prepare(queryString);
    147149
     
    217219void SearchDialog::itemSelected(int i)
    218220{
    219221    unsigned int id = ((SearchListBoxItem*)listbox->item(i))->getId();
    220     whereClause = QString("WHERE intid='%1';").arg(id);
     222    whereClause = QString("WHERE song_id='%1';").arg(id);
    221223    done(0);
    222224}
    223225
  • mythmusic/mythmusic/playlist.h

     
    8383    void loadPlaylist(QString a_name, QString a_host);
    8484    void loadPlaylistByID(int id, QString a_host);
    8585
    86     void savePlaylist(QString a_name);
    87     void saveNewPlaylist(QString a_host);
     86    void savePlaylist(QString a_name, QString a_host);
    8887
    8988    void putYourselfOnTheListView(UIListGenericTree *a_parent);
    9089
  • mythmusic/mythmusic/cdrip.h

     
    3838    void reject();
    3939
    4040  private:
    41     void fillComboBox (MythComboBox &, const QString &);
    42 
    4341    int ripTrack(QString &cddevice, Encoder *encoder, int tracknum);
    4442    static QString fixFileToken(QString token);
    4543    void handleFileTokens(QString &filename, Metadata *track);
  • mythmusic/mythmusic/metadata.cpp

     
    3131
    3232Metadata& Metadata::operator=(Metadata *rhs)
    3333{
    34     artist = rhs->Artist();
    35     compilation_artist = rhs->CompilationArtist();
    36     album = rhs->Album();
    37     title = rhs->Title();
    38     formattedartist = rhs->FormatArtist();
    39     formattedtitle = rhs->FormatTitle();
    40     genre = rhs->Genre();
    41     year = rhs->Year();
    42     tracknum = rhs->Track();
    43     length = rhs->Length();
    44     rating = rhs->Rating();
    45     lastplay = rhs->LastPlayStr();
    46     playcount = rhs->Playcount();
    47     compilation = rhs->Compilation();
    48     id = rhs->ID();
    49     filename = rhs->Filename();
    50     changed = rhs->hasChanged();
     34    artist = rhs->artist;
     35    compilation_artist = rhs->compilation_artist;
     36    album = rhs->album;
     37    title = rhs->title;
     38    formattedartist = rhs->formattedartist;
     39    formattedtitle = rhs->formattedtitle;
     40    genre = rhs->genre;
     41    year = rhs->year;
     42    tracknum = rhs->tracknum;
     43    length = rhs->length;
     44    rating = rhs->rating;
     45    lastplay = rhs->lastplay;
     46    playcount = rhs->playcount;
     47    compilation = rhs->compilation;
     48    id = rhs->id;
     49    filename = rhs->filename;
     50    changed = rhs->changed;
    5151
    5252    return *this;
    5353}
     
    6262void Metadata::persist()
    6363{
    6464    MSqlQuery query(MSqlQuery::InitCon());
    65     query.prepare("UPDATE musicmetadata set rating = :RATING , "
    66                   "playcount = :PLAYCOUNT , lastplay = :LASTPLAY "
    67                   "where intid = :ID ;");
     65    query.prepare("UPDATE music_songs set rating = :RATING , "
     66                  "numplays = :PLAYCOUNT , lastplay = :LASTPLAY "
     67                  "where song_id = :ID ;");
    6868    query.bindValue(":RATING", rating);
    6969    query.bindValue(":PLAYCOUNT", playcount);
    7070    query.bindValue(":LASTPLAY", lastplay);
     
    100100        sqlfilename.remove(0, m_startdir.length());
    101101
    102102    MSqlQuery query(MSqlQuery::InitCon());
    103     query.prepare("SELECT artist,compilation_artist,album,title,genre,year,tracknum,"
    104                   "length,intid,rating,playcount,lastplay,compilation,format FROM "
    105                   "musicmetadata WHERE filename = :FILENAME ;");
     103    query.prepare("SELECT music_artists.artist_name, music_comp_artists.artist_name AS compilation_artist, "
     104                  "music_albums.album_name, music_songs.name, music_genres.genre, music_songs.year, "
     105                  "music_songs.track, music_songs.length, music_songs.song_id, music_songs.rating, "
     106                  "music_songs.numplays, music_songs.lastplay, music_albums.compilation, "
     107                  "music_songs.format "
     108                  "FROM music_songs "
     109                  "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     110                  "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
     111                  "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
     112                  "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id "
     113                  "WHERE music_songs.filename = :FILENAME ;");
    106114    query.bindValue(":FILENAME", sqlfilename.utf8());
    107115
    108116    if (query.exec() && query.isActive() && query.size() > 0)
     
    150158    // Don't update the database if a song with the exact same
    151159    // metadata is already there
    152160    MSqlQuery query(MSqlQuery::InitCon());
    153     query.prepare("SELECT filename FROM musicmetadata WHERE "
    154                   "( ( artist = :ARTIST ) AND "
    155                   "( compilation_artist = :COMPILATION_ARTIST ) "
    156                   "( album = :ALBUM ) AND ( title = :TITLE ) "
    157                   "AND ( genre = :GENRE ) AND "
    158                   "( year = :YEAR ) AND ( tracknum = :TRACKNUM ) "
    159                   "AND ( length = :LENGTH ) "
    160                   "AND ( format = :FORMAT) );");
     161    query.prepare("SELECT music_songs.filename "
     162                  "FROM music_songs "
     163                  "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     164                  "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
     165                  "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
     166                  "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id "
     167                  "WHERE music_artists.artist_name = :ARTIST"
     168                  " AND music_comp_artists.artist_name = :COMPILATION_ARTIST"
     169                  " AND music_albums.album_name = :ALBUM"
     170                  " AND music_songs.name = :TITLE"
     171                  " AND music_genres.genre = :GENRE"
     172                  " AND music_songs.year = :YEAR"
     173                  " AND music_songs.track = :TRACKNUM"
     174                  " AND music_songs.length = :LENGTH"
     175                  " AND music_songs.format = :FORMAT ;");
     176
    161177    query.bindValue(":ARTIST", artist.utf8());
    162178    query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
    163179    query.bindValue(":ALBUM", album.utf8());
     
    171187    if (query.exec() && query.isActive() && query.size() > 0)
    172188        return;
    173189
    174     query.prepare("INSERT INTO musicmetadata "
    175                   "(artist,   compilation_artist, album,      title,  "
    176                   " genre,    year,               tracknum,   length, "
    177                   " filename, compilation,        date_added, date_modified, "
    178                   " format ) "
    179                   "VALUES "
    180                   "(:ARTIST,  :COMPILATION_ARTIST,:ALBUM,     :TITLE,   "
    181                   " :GENRE,   :YEAR,              :TRACKNUM,  :LENGTH,  "
    182                   " :FILENAME,:COMPILATION,       :DATE_ADDED,:DATE_MOD,"
    183                   " :FORMAT)");
     190    // Load the artist id or insert it and get the id
     191    unsigned int artistId;
     192    query.prepare("SELECT artist_id FROM music_artists "
     193                  "WHERE artist_name = :ARTIST ;");
    184194    query.bindValue(":ARTIST", artist.utf8());
    185     query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
     195
     196    if (!query.exec() || !query.isActive())
     197    {
     198        MythContext::DBError("music select artist id", query);
     199        return;
     200    }
     201    if (query.size() > 0)
     202    {
     203        query.next();
     204        artistId = query.value(0).toInt();
     205    }
     206    else
     207    {
     208        query.prepare("INSERT INTO music_artists (artist_name) VALUES (:ARTIST);");
     209        query.bindValue(":ARTIST", artist.utf8());
     210
     211        if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
     212        {
     213            MythContext::DBError("music insert artist", query);
     214            return;
     215        }
     216        artistId = query.lastInsertId().toInt();
     217    }
     218
     219    // Compilation Artist
     220    unsigned int compilationArtistId;
     221    query.prepare("SELECT artist_id FROM music_artists "
     222                  "WHERE artist_name = :ARTIST ;");
     223    query.bindValue(":ARTIST", compilation_artist.utf8());
     224    if (!query.exec() || !query.isActive())
     225    {
     226        MythContext::DBError("music select compilation artist id", query);
     227        return;
     228    }
     229    if (query.size() > 0)
     230    {
     231        query.next();
     232        compilationArtistId = query.value(0).toInt();
     233    }
     234    else
     235    {
     236        query.prepare("INSERT INTO music_artists (artist_name) VALUES (:ARTIST);");
     237        query.bindValue(":ARTIST", compilation_artist.utf8());
     238
     239        if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
     240        {
     241            MythContext::DBError("music insert compilation artist", query);
     242            return;
     243        }
     244        compilationArtistId = query.lastInsertId().toInt();
     245    }
     246
     247    // Album
     248    unsigned int albumId;
     249    query.prepare("SELECT album_id FROM music_albums "
     250                  "WHERE artist_id = :COMP_ARTIST_ID "
     251                  " AND album_name = :ALBUM ;");
     252    query.bindValue(":COMP_ARTIST_ID", compilationArtistId);
    186253    query.bindValue(":ALBUM", album.utf8());
     254    if (!query.exec() || !query.isActive())
     255    {
     256        MythContext::DBError("music select album id", query);
     257        return;
     258    }
     259    if (query.size() > 0)
     260    {
     261        query.next();
     262        albumId = query.value(0).toInt();
     263    }
     264    else
     265    {
     266        query.prepare("INSERT INTO music_albums (artist_id, album_name, compilation, year) VALUES (:COMP_ARTIST_ID, :ALBUM, :COMPILATION, :YEAR);");
     267        query.bindValue(":COMP_ARTIST_ID", compilationArtistId);
     268        query.bindValue(":ALBUM", album.utf8());
     269        query.bindValue(":COMPILATION", compilation);
     270        query.bindValue(":YEAR", year);
     271
     272        if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
     273        {
     274            MythContext::DBError("music insert album", query);
     275            return;
     276        }
     277        albumId = query.lastInsertId().toInt();
     278    }
     279
     280    // Genres
     281    unsigned int genreId;
     282    query.prepare("SELECT genre_id FROM music_genres "
     283                  "WHERE genre = :GENRE ;");
     284    query.bindValue(":GENRE", genre.utf8());
     285    if (!query.exec() || !query.isActive())
     286    {
     287        MythContext::DBError("music select genre id", query);
     288        return;
     289    }
     290    if (query.size() > 0)
     291    {
     292        query.next();
     293        genreId = query.value(0).toInt();
     294    }
     295    else
     296    {
     297        query.prepare("INSERT INTO music_genres (genre) VALUES (:GENRE);");
     298        query.bindValue(":GENRE", genre.utf8());
     299
     300        if (!query.exec() || !query.isActive() || query.numRowsAffected() <= 0)
     301        {
     302            MythContext::DBError("music insert genre", query);
     303            return;
     304        }
     305        genreId = query.lastInsertId().toInt();
     306    }
     307
     308    // We have all the id's now. We can insert it.
     309    QString strQuery;
     310    if (id < 1)
     311    {
     312        strQuery = "INSERT INTO music_songs ("
     313                   " artist_id, album_id,  name,         genre_id,"
     314                   " year,      track,     length,       filename,"
     315                   " rating,    format,    date_entered, date_modified ) "
     316                   "VALUES ("
     317                   " :ARTIST,   :ALBUM,    :TITLE,       :GENRE,"
     318                   " :YEAR,     :TRACKNUM, :LENGTH,      :FILENAME,"
     319                   " :RATING,   :FORMAT,   :DATE_ADD,    :DATE_MOD );";
     320    }
     321    else
     322    {
     323        strQuery = "UPDATE music_songs SET"
     324                   "  artist_id = :ARTIST"
     325                   ", album_id = :ALBUM"
     326                   ", name = :TITLE"
     327                   ", genre_id = :GENRE"
     328                   ", year = :YEAR"
     329                   ", track = :TRACKNUM"
     330                   ", length = :LENGTH"
     331                   ", filename = :FILENAME"
     332                   ", rating = :RATING"
     333                   ", format = :FORMAT"
     334                   ", date_modified = :DATE_MOD "
     335                   "WHERE song_id= :ID ;";
     336    }
     337
     338    query.prepare(strQuery);
     339    /*
     340    query.prepare("INSERT INTO music_songs "
     341                  "  (artist_id, album_id,     name,"
     342                  "   genre_id,  year,         track,                length,"
     343                  "   filename,  date_entered, date_modified,"
     344                  "   format,    size,         bitrate) "
     345                  "VALUES "
     346                  "  (:ARTIST,   :ALBUM,       :TITLE,"
     347                  "   :GENRE,    :YEAR,        :TRACKNUM,            :LENGTH,"
     348                  "   :FILENAME, :DATE_ADDED,  :DATE_MOD,"
     349                  "   :FORMAT,   :FILESIZE,    :BITRATE)"
     350                  );
     351    */
     352    query.bindValue(":ARTIST", artistId);
     353    query.bindValue(":ALBUM", albumId);
    187354    query.bindValue(":TITLE", title.utf8());
    188     query.bindValue(":GENRE", genre.utf8());
     355    query.bindValue(":GENRE", genreId);
    189356    query.bindValue(":YEAR", year);
    190357    query.bindValue(":TRACKNUM", tracknum);
    191358    query.bindValue(":LENGTH", length);
    192359    query.bindValue(":FILENAME", sqlfilename.utf8());
    193     query.bindValue(":COMPILATION", compilation);
    194     query.bindValue(":DATE_ADDED",  QDateTime::currentDateTime());
    195     query.bindValue(":DATE_MOD",    QDateTime::currentDateTime());
     360    query.bindValue(":RATING", rating);
    196361    query.bindValue(":FORMAT", format);
    197    
     362    query.bindValue(":DATE_MOD", QDateTime::currentDateTime());
     363
     364    if (id < 1)
     365        query.bindValue(":DATE_ADDED",  QDateTime::currentDateTime());
     366    else
     367        query.bindValue(":ID", id);
     368
    198369    query.exec();
    199370
    200     // easiest way to ensure we've got 'id' filled.
    201     fillData();
     371    if (id < 1 && query.isActive() && 1 == query.numRowsAffected())
     372        id = query.lastInsertId().toInt();
    202373}
    203374
    204375// Default values for formats
     
    328499}
    329500
    330501
    331 void Metadata::updateDatabase()
    332 {
    333     // only save to DB if something changed
    334     //if (!hasChanged())
    335     //    return;
    336 
    337     if (artist == "")
    338         artist = QObject::tr("Unknown Artist");
    339     if (album == "")
    340         album = QObject::tr("Unknown Album");
    341     if (title == "")
    342         title = filename;
    343     if (genre == "")
    344         genre = QObject::tr("Unknown Genre");
    345 
    346     MSqlQuery query(MSqlQuery::InitCon());
    347 
    348     query.prepare("UPDATE musicmetadata    "
    349                   "SET artist   = :ARTIST,   "
    350                   "    album    = :ALBUM,    "
    351                   "    title    = :TITLE,    "
    352                   "    genre    = :GENRE,    "
    353                   "    year     = :YEAR,     "
    354                   "    tracknum = :TRACKNUM, "
    355                   "    rating   = :RATING,   "
    356                   "    date_modified      = :DATE_MODIFIED, "
    357                   "    compilation        = :COMPILATION,   "
    358                   "    compilation_artist = :COMPILATION_ARTIST, "
    359                   "    format             = :FORMAT "
    360                   "WHERE intid = :ID;");
    361     query.bindValue(":ARTIST",             artist.utf8());
    362     query.bindValue(":ALBUM",              album.utf8());
    363     query.bindValue(":TITLE",              title.utf8());
    364     query.bindValue(":GENRE",              genre.utf8());
    365     query.bindValue(":YEAR",               year);
    366     query.bindValue(":TRACKNUM",           tracknum);
    367     query.bindValue(":RATING",             rating);
    368     query.bindValue(":DATE_MODIFIED",      QDateTime::currentDateTime());
    369     query.bindValue(":COMPILATION",        compilation);
    370     query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
    371     query.bindValue(":FORMAT", format);
    372     query.bindValue(":ID", id);
    373 
    374     if (!query.exec())
    375          MythContext::DBError("Update musicmetadata", query);
    376 }
    377 
    378 
    379502void Metadata::setField(const QString &field, const QString &data)
    380503{
    381504    if (field == "artist")
     
    426549    }
    427550}
    428551
    429 void Metadata::fillData()
    430 {
    431     if (title == "")
    432         return;
    433 
    434     QString thequery = "SELECT artist,compilation_artist,album,title,genre,year,tracknum,length,"
    435                        "filename,intid,rating,playcount,lastplay,compilation,format "
    436                        "FROM musicmetadata WHERE title = :TITLE";
    437 
    438     if (album != "")
    439         thequery += " AND album = :ALBUM";
    440     if (artist != "")
    441         thequery += " AND artist = :ARTIST";
    442     if (compilation_artist != "")
    443         thequery += " AND compilation_artist = :COMPILATION_ARTIST";
    444 
    445     thequery += ";";
    446 
    447     MSqlQuery query(MSqlQuery::InitCon());
    448     query.prepare(thequery);
    449     query.bindValue(":TITLE", title.utf8());
    450     query.bindValue(":ALBUM", album.utf8());
    451     query.bindValue(":ARTIST", artist.utf8());
    452     query.bindValue(":COMPILATION_ARTIST", compilation_artist.utf8());
    453 
    454     if (query.exec() && query.isActive() && query.size() > 0)
    455     {
    456         query.next();
    457 
    458         artist = QString::fromUtf8(query.value(0).toString());
    459         compilation_artist = QString::fromUtf8(query.value(1).toString());
    460         album = QString::fromUtf8(query.value(2).toString());
    461         title = QString::fromUtf8(query.value(3).toString());
    462         genre = QString::fromUtf8(query.value(4).toString());
    463         year = query.value(5).toInt();
    464         tracknum = query.value(6).toInt();
    465         length = query.value(7).toInt();
    466         filename = QString::fromUtf8(query.value(8).toString());
    467         id = query.value(9).toUInt();
    468         rating = query.value(10).toInt();
    469         playcount = query.value(11).toInt();
    470         lastplay = query.value(12).toString();
    471         compilation = (query.value(13).toInt() > 0);
    472         format = query.value(14).toString();
    473 
    474         if (!filename.contains("://"))
    475             filename = m_startdir + filename;
    476     }
    477 }
    478 
    479 void Metadata::fillDataFromID()
    480 {       
    481     if (id == 0)
    482         return;
    483        
    484     MSqlQuery query(MSqlQuery::InitCon());
    485     query.prepare("SELECT title,artist,compilation_artist,album,title,genre,year,tracknum,"
    486                   "length,filename,rating,playcount,lastplay,compilation,format FROM "
    487                   "musicmetadata WHERE intid = :ID ;");
    488     query.bindValue(":ID", id);
    489        
    490     if (query.exec() && query.isActive() && query.numRowsAffected() > 0)
    491     {
    492         query.next();
    493 
    494         title = QString::fromUtf8(query.value(0).toString());
    495         artist = QString::fromUtf8(query.value(1).toString());
    496         compilation_artist = QString::fromUtf8(query.value(2).toString());
    497         album = QString::fromUtf8(query.value(3).toString());
    498         title = QString::fromUtf8(query.value(4).toString());
    499         genre = QString::fromUtf8(query.value(5).toString());
    500         year = query.value(6).toInt();
    501         tracknum = query.value(7).toInt();
    502         length = query.value(8).toInt();
    503         filename = QString::fromUtf8(query.value(9).toString());
    504         rating = query.value(10).toInt();
    505         playcount = query.value(11).toInt();
    506         lastplay = query.value(12).toString();
    507         compilation = (query.value(13).toInt() > 0);
    508         format = query.value(14).toString();
    509 
    510         if (!filename.contains("://"))
    511             filename = m_startdir + filename;
    512     }
    513 }
    514 
    515552void Metadata::decRating()
    516553{
    517554    if (rating > 0)
     
    553590    changed = true;
    554591}
    555592
     593QStringList Metadata::fillFieldList(QString field)
     594{
     595    QStringList searchList;
     596    searchList.clear();
     597
     598    MSqlQuery query(MSqlQuery::InitCon());
     599    if ("artist" == field || "compilation_artist" == field)
     600    {
     601        query.prepare("SELECT artist_name FROM music_artists ORDER BY artist_name;");
     602    }
     603    else if ("album" == field)
     604    {
     605        query.prepare("SELECT album_name FROM music_albums ORDER BY album_name;");
     606    }
     607    else if ("title" == field)
     608    {
     609        query.prepare("SELECT name FROM music_songs ORDER BY name;");
     610    }
     611    else if ("genre" == field)
     612    {
     613        query.prepare("SELECT genre FROM music_genres ORDER BY genre;");
     614    }
     615    else
     616    {
     617        return searchList;
     618    }
     619
     620    if (query.exec() && query.isActive() && query.size())
     621    {
     622        while (query.next())
     623        {
     624            searchList << QString::fromUtf8(query.value(0).toString());
     625        }
     626    }
     627    return searchList;
     628}
     629
    556630MetadataLoadingThread::MetadataLoadingThread(AllMusic *parent_ptr)
    557631{
    558632    parent = parent_ptr;
     
    648722void AllMusic::resync()
    649723{
    650724    done_loading = false;
    651     QString aquery =    "SELECT intid, artist, compilation_artist, album, title, genre, "
    652                         "year, tracknum, length, filename, rating, "
    653                         "lastplay, playcount, compilation, format "
    654                         "FROM musicmetadata "
    655                         "ORDER BY intid;";
    656725
     726    QString aquery = "SELECT music_songs.song_id, music_artists.artist_name, music_comp_artists.artist_name AS compilation_artist, "
     727                     "music_albums.album_name, music_songs.name, music_genres.genre, music_songs.year, "
     728                     "music_songs.track, music_songs.length, music_songs.filename, "
     729                     "music_songs.rating, music_songs.numplays, music_songs.lastplay, music_albums.compilation, "
     730                     "music_songs.format "
     731                     "FROM music_songs "
     732                     "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     733                     "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
     734                     "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
     735                     "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id "
     736                     "ORDER BY music_songs.song_id;";
     737
    657738    QString filename, artist, album, title;
    658739
    659740    MSqlQuery query(MSqlQuery::InitCon());
     
    696777                query.value(7).toInt(),
    697778                query.value(8).toInt(),
    698779                query.value(0).toInt(),
    699                 query.value(10).toInt(),
    700                 query.value(12).toInt(),
    701                 query.value(11).toString(),
    702                 (query.value(13).toInt() > 0),
    703                 query.value(14).toString());
    704            
     780                query.value(10).toInt(), //rating
     781                query.value(11).toInt(), //playcount
     782                query.value(12).toString(), //lastplay
     783                (query.value(13).toInt() > 0), //compilation
     784                query.value(14).toString()); //format
     785
    705786            //  Don't delete temp, as PtrList now owns it
    706787            all_music.append(temp);
    707788
  • mythmusic/mythmusic/dbcheck.cpp

     
    99#include "mythtv/mythcontext.h"
    1010#include "mythtv/mythdbcon.h"
    1111
    12 const QString currentDatabaseVersion = "1005";
     12const QString currentDatabaseVersion = "1006";
    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"CREATE TABLE music_albums ("
     332"    album_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
     333"    artist_id int(11) unsigned NOT NULL default '0',"
     334"    album_name varchar(255) NOT NULL default '',"
     335"    year smallint(6) NOT NULL default '0',"
     336"    compilation tinyint(1) unsigned NOT NULL default '0',"
     337"    INDEX idx_album_name(album_name)"
     338");",
     339"CREATE TABLE music_artists ("
     340"    artist_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
     341"    artist_name varchar(255) NOT NULL default '',"
     342"    INDEX idx_artist_name(artist_name)"
     343");",
     344"CREATE TABLE music_genres ("
     345"    genre_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
     346"    genre varchar(25) NOT NULL default '',"
     347"    INDEX idx_genre(genre)"
     348");",
     349"CREATE TABLE music_playlists ("
     350"    playlist_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
     351"    playlist_name varchar(255) NOT NULL default '',"
     352"    playlist_songs text NOT NULL default '',"
     353"    last_accessed timestamp NOT NULL,"
     354"    length int(11) unsigned NOT NULL default '0',"
     355"    songcount smallint(8) unsigned NOT NULL default '0',"
     356"    hostname VARCHAR(255) NOT NULL default ''"
     357");",
     358"CREATE TABLE music_songs ("
     359"    song_id int(11) unsigned NOT NULL auto_increment PRIMARY KEY,"
     360"    filename text NOT NULL default '',"
     361"    name varchar(255) NOT NULL default '',"
     362"    track smallint(6) unsigned NOT NULL default '0',"
     363"    artist_id int(11) unsigned NOT NULL default '0',"
     364"    album_id int(11) unsigned NOT NULL default '0',"
     365"    genre_id int(11) unsigned NOT NULL default '0',"
     366"    year smallint(6) NOT NULL default '0',"
     367"    length int(11) unsigned NOT NULL default '0',"
     368"    numplays int(11) unsigned NOT NULL default '0',"
     369"    rating tinyint(4) unsigned NOT NULL default '0',"
     370"    lastplay timestamp NOT NULL,"
     371"    date_entered datetime default NULL,"
     372"    date_modified datetime default NULL,"
     373"    format varchar(4) NOT NULL default '0',"
     374"    mythdigest VARCHAR(255),"
     375"    size BIGINT(20) unsigned,"
     376"    description VARCHAR(255),"
     377"    comment VARCHAR(255),"
     378"    disc_count SMALLINT(5) UNSIGNED DEFAULT '0',"
     379"    disc_number SMALLINT(5) UNSIGNED DEFAULT '0',"
     380"    track_count SMALLINT(5) UNSIGNED DEFAULT '0',"
     381"    start_time INT(10) UNSIGNED DEFAULT '0',"
     382"    stop_time INT(10) UNSIGNED,"
     383"    eq_preset VARCHAR(255),"
     384"    relative_volume TINYINT DEFAULT '0',"
     385"    bpm SMALLINT(5) UNSIGNED,"
     386"    INDEX idx_name(name),"
     387"    INDEX idx_mythdigest(mythdigest)"
     388");",
     389"CREATE TABLE music_stats ("
     390"    num_artists smallint(5) unsigned NOT NULL default '0',"
     391"    num_albums smallint(5) unsigned NOT NULL default '0',"
     392"    num_songs mediumint(8) unsigned NOT NULL default '0',"
     393"    num_genres tinyint(3) unsigned NOT NULL default '0',"
     394"    total_time varchar(12) NOT NULL default '0',"
     395"    total_size varchar(10) NOT NULL default '0'"
     396");",
     397"RENAME TABLE smartplaylist TO music_smartplaylists;",
     398"RENAME TABLE smartplaylistitem TO music_smartplaylist_items;",
     399"RENAME TABLE smartplaylistcategory TO music_smartplaylist_categories;",
     400// Run necessary SQL to migrate the table structure
     401"CREATE TEMPORARY TABLE tmp_artists"
     402"  SELECT DISTINCT artist FROM musicmetadata;",
     403"INSERT INTO tmp_artists"
     404"  SELECT DISTINCT compilation_artist"
     405"  FROM musicmetadata"
     406"  WHERE compilation_artist<>artist;",
     407"INSERT INTO music_artists (artist_name) SELECT DISTINCT artist FROM tmp_artists;",
     408"INSERT INTO music_albums (artist_id, album_name, year, compilation) "
     409"  SELECT artist_id, album, ROUND(AVG(year)) AS year, IF(SUM(compilation),1,0) AS compilation"
     410"  FROM musicmetadata"
     411"  LEFT JOIN music_artists ON compilation_artist=artist_name"
     412"  GROUP BY artist_id, album;",
     413"INSERT INTO music_genres (genre) SELECT DISTINCT genre FROM musicmetadata;",
     414"INSERT INTO music_songs "
     415"   (song_id, artist_id, album_id, genre_id, year, lastplay,"
     416"    date_entered, date_modified, name, track, length, size, numplays,"
     417"    rating, filename)"
     418"  SELECT intid, ma.artist_id, mb.album_id, mg.genre_id, mmd.year, lastplay,"
     419"         date_added, date_modified, title, tracknum, length, IFNULL(size,0), playcount,"
     420"         rating, filename"
     421"  FROM musicmetadata AS mmd"
     422"  LEFT JOIN music_artists AS ma ON mmd.artist=ma.artist_name"
     423"  LEFT JOIN music_artists AS mc ON mmd.compilation_artist=mc.artist_name"
     424"  LEFT JOIN music_albums AS mb ON mmd.album=mb.album_name AND mc.artist_id=mb.artist_id"
     425"  LEFT JOIN music_genres AS mg ON mmd.genre=mg.genre;",
     426"INSERT INTO music_playlists"
     427"  (playlist_id,playlist_name,playlist_songs,hostname)"
     428"  SELECT playlistid, name, songlist, hostname"
     429"  FROM musicplaylist;",
     430// Set all playlists to be global by killing the hostname
     431"UPDATE music_playlists"
     432"  SET hostname=''"
     433"  WHERE playlist_name='default_playlist_storage'"
     434"    OR playlist_name='backup_playlist_storage';",
     435//"DROP TABLE musicmetadata;",
     436//"DROP TABLE musicplaylist;",
     437//RENAME TABLE music_smartplaylists TO smartplaylist;RENAME TABLE music_smartplaylist_categories TO smartplaylistcategory;RENAME TABLE music_smartplaylist_items TO smartplaylistitem; DROP TABLE music_albums; DROP TABLE music_artists; DROP TABLE music_genres; DROP TABLE music_playlists; DROP TABLE music_songs; DROP TABLE music_stats;UPDATE settings SET data=1005 WHERE value='MusicDBSchemaVer';
     438""
     439};
     440        performActualUpdate(updates, "1006", dbver);
     441    }
    326442}
    327443
  • mythmusic/mythmusic/playlist.cpp

     
    3535    if (index_value > 0) // Normal Track
    3636        label = all_available_music->getLabel(index_value, &bad_reference);
    3737    else if (index_value < 0)
    38         label = grandparent->getPlaylistName( index_value,  bad_reference);
     38        label = grandparent->getPlaylistName( (-1 * index_value),  bad_reference);
    3939    else
    4040    {
    4141        cerr << "playlist.o: Not sure how I got 0 as a track number, but "
     
    6969{
    7070    // XXX SPEED THIS UP
    7171    // Should be a straight lookup against cached index
    72     bool result = false;
    7372    Track *it;
    7473
    7574    for (it = songs.first(); it; it = songs.next())
    7675    {
    7776        if (it->getValue() == a_track_id && it->getCDFlag() == cd_flag)
    7877        {
    79             result = true;
     78            return true;
    8079        }
    8180    } 
    8281
    83     return result;   
     82    return false;
    8483}
    8584
    8685void Playlist::copyTracks(Playlist *to_ptr, bool update_display)
     
    327326    all_other_playlists->clear();
    328327
    329328    MSqlQuery query(MSqlQuery::InitCon());
    330     query.prepare("SELECT playlistid FROM musicplaylist "
    331                   "WHERE name != :DEFAULT  "
    332                   "AND name != :BACKUP  "
    333                   "AND hostname = :HOST ORDER BY playlistid ;");
     329    query.prepare("SELECT playlist_id FROM music_playlists "
     330                  "WHERE playlist_name != :DEFAULT"
     331                  " AND playlist_name != :BACKUP "
     332                  " AND (hostname = '' OR hostname = :HOST) "
     333                  "ORDER BY playlist_id;");
    334334    query.bindValue(":DEFAULT", "default_playlist_storage");
    335335    query.bindValue(":BACKUP", "backup_playlist_storage");
    336336    query.bindValue(":HOST", my_host);
     
    469469    }
    470470   
    471471    MSqlQuery query(MSqlQuery::InitCon());
    472     query.prepare("SELECT playlistid, name, songlist FROM "
    473                   "musicplaylist WHERE name = :NAME AND "
    474                   "hostname = :HOST ;");
    475     query.bindValue(":NAME", a_name);
     472
     473    if (name == "default_playlist_storage" || name == "backup_playlist_storage")
     474    {
     475        query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
     476                      "FROM  music_playlists "
     477                      "WHERE playlist_name = :NAME"
     478                      " AND hostname = :HOST;");
     479    }
     480    else
     481    {
     482        // Technically this is never called as this function is only used to load
     483        // the default/backup playlists.
     484        query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
     485                      "FROM music_playlists "
     486                      "WHERE playlist_name = :NAME"
     487                      " AND (hostname = '' OR hostname = :HOST);");
     488    }
     489    query.bindValue(":NAME", a_name.utf8());
    476490    query.bindValue(":HOST", a_host);
    477491
    478492    if (query.exec() && query.size() > 0)
    479493    {
    480494        while (query.next())
    481495        {
    482             this->playlistid = query.value(0).toInt();
    483             this->name = QString::fromUtf8(query.value(1).toString());
    484             this->raw_songlist = query.value(2).toString();
     496            playlistid = query.value(0).toInt();
     497            name = QString::fromUtf8(query.value(1).toString());
     498            raw_songlist = query.value(2).toString();
    485499        }
    486500        if (name == "default_playlist_storage")
    487501            name = "the user should never see this";
     
    490504    }
    491505    else
    492506    {
    493         name = a_name;
    494         saveNewPlaylist(a_host);
     507        // Asked me to load a playlist I can't find so let's create a new one :)
     508        playlistid = 0; // Be safe just in case we call load over the top
     509                        // of an existing playlist
     510        raw_songlist = "";
     511        savePlaylist(a_name, a_host);
    495512        changed = true;
    496513    }
    497514}
     
    499516void Playlist::loadPlaylistByID(int id, QString a_host)
    500517{
    501518    MSqlQuery query(MSqlQuery::InitCon());
    502     query.prepare("SELECT playlistid, name, songlist FROM "
    503                   "musicplaylist WHERE playlistid = :ID AND "
    504                   "hostname = :HOST ;");
     519    query.prepare("SELECT playlist_id, playlist_name, playlist_songs "
     520                  "FROM music_playlists "
     521                  "WHERE playlist_id = :ID"
     522                  " AND (hostname = '' OR hostname = :HOST);");
    505523    query.bindValue(":ID", id);
    506524    query.bindValue(":HOST", a_host);
    507525
     
    509527
    510528    while (query.next())
    511529    {
    512         this->playlistid = query.value(0).toInt();
    513         this->name = QString::fromUtf8(query.value(1).toString());
    514         this->raw_songlist = query.value(2).toString();
     530        playlistid = query.value(0).toInt();
     531        name = QString::fromUtf8(query.value(1).toString());
     532        raw_songlist = query.value(2).toString();
    515533    }
    516534
    517535    if (name == "default_playlist_storage")
     
    570588
    571589void Playlist::fillSonglistFromSongs()
    572590{
    573     bool first = true;
    574     QString a_list;
     591    QString a_list = "";
    575592    Track *it;
    576593    for (it = songs.first(); it; it = songs.next())
    577594    {
    578595        if (!it->getCDFlag())
    579596        {
    580             if (first)
    581             {
    582                 first = false;
    583                 a_list = QString("%1").arg(it->getValue());
    584             }
    585             else
    586                 a_list += QString(",%1").arg(it->getValue());
     597            a_list += QString(",%1").arg(it->getValue());
    587598        }
    588599    }
    589600
    590     raw_songlist = a_list;
     601    raw_songlist = "";
     602    if (a_list.length() > 1)
     603        raw_songlist = a_list.remove(0, 1);
    591604}
    592605
    593606void Playlist::fillSonglistFromQuery(QString whereClause,
     
    604617
    605618    QString theQuery;
    606619
    607     theQuery = "SELECT intid FROM musicmetadata ";
     620    theQuery = "SELECT song_id FROM music_songs "
     621               "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     622               "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
     623               "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id ";
    608624
    609625    if (whereClause.length() > 0)
    610626      theQuery += whereClause;
     
    719735    int limitTo;
    720736   
    721737    query.prepare("SELECT smartplaylistid, matchtype, orderby, limitto "
    722                   "FROM smartplaylist WHERE categoryid = :CATEGORYID AND name = :NAME;");
     738                  "FROM music_smartplaylists WHERE categoryid = :CATEGORYID AND name = :NAME;");
    723739    query.bindValue(":NAME", name.utf8());
    724740    query.bindValue(":CATEGORYID", categoryID);
    725741       
    726742    if (query.exec())
    727743    {
    728         if (query.isActive() && query.numRowsAffected() > 0)
     744        if (query.isActive() && query.size() > 0)
    729745        {
    730746            query.first();
    731747            ID = query.value(0).toInt();
     
    749765    QString whereClause = "WHERE ";
    750766   
    751767    query.prepare("SELECT field, operator, value1, value2 "
    752                   "FROM smartplaylistitem WHERE smartplaylistid = :ID;");
     768                  "FROM music_smartplaylist_items WHERE smartplaylistid = :ID;");
    753769    query.bindValue(":ID", ID);
    754770    query.exec();
    755     if (query.isActive() && query.numRowsAffected() > 0)
     771    if (query.isActive() && query.size() > 0)
    756772    {
    757773        bool bFirst = true;
    758774        while (query.next())
     
    770786            }
    771787        }
    772788    }
    773    
     789
    774790    // add order by clause
    775791    whereClause += getOrderBySQL(orderBy);
    776    
     792
    777793    // add limit
    778794    if (limitTo > 0)
    779         whereClause +=  " LIMIT " + QString::number(limitTo); 
     795        whereClause +=  " LIMIT " + QString::number(limitTo);
    780796
    781797    fillSonglistFromQuery(whereClause, removeDuplicates, insertOption, currentTrackID);
    782798}
    783    
    784 void Playlist::savePlaylist(QString a_name)
     799
     800void Playlist::savePlaylist(QString a_name, QString a_host)
    785801{
    786     name = name.simplifyWhiteSpace();
     802    name = a_name.simplifyWhiteSpace();
    787803    if (name.length() < 1)
    788         return;
    789 
    790     fillSonglistFromSongs();
    791 
    792     MSqlQuery query(MSqlQuery::InitCon());
    793     query.prepare("SELECT NULL FROM musicplaylist WHERE playlistid = :ID ;");
    794     query.bindValue(":ID", playlistid);
    795 
    796     if (query.exec() && query.isActive() && query.size() > 0)
    797804    {
    798         query.prepare("UPDATE musicplaylist SET songlist = :LIST , "
    799                       "name = :NAME WHERE playlistid = :ID ;");
    800         query.bindValue(":LIST", raw_songlist);
    801         query.bindValue(":NAME", a_name.utf8());
    802         query.bindValue(":ID", playlistid);
    803     }
    804     else
    805     {
    806         query.prepare("INSERT INTO musicplaylist (name,songlist) "
    807                       "VALUES(:NAME, :LIST);");
    808         query.bindValue(":LIST", raw_songlist);
    809         query.bindValue(":NAME", a_name.utf8());
    810     }
    811 
    812     query.exec();
    813 }
    814 
    815 void Playlist::saveNewPlaylist(QString a_host)
    816 {
    817     name = name.simplifyWhiteSpace();
    818     if(name.length() < 1)
    819     {
    820805        cerr << "playlist.o: Not going to save a playlist with no name" << endl ;
    821806        return;
    822807    }
    823808
    824     if(a_host.length() < 1)
     809    if (a_host.length() < 1)
    825810    {
    826811        cerr << "playlist.o: Not going to save a playlist with no hostname" << endl;
    827812        return;
    828813    }
     814    if (name.length() < 1)
     815        return;
    829816
    830817    fillSonglistFromSongs();
    831    
    832818    MSqlQuery query(MSqlQuery::InitCon());
    833     query.prepare("INSERT musicplaylist (name, hostname) "
    834                   "VALUES(:NAME, :HOST);");
    835     query.bindValue(":NAME", name.utf8());
    836     query.bindValue(":HOST", a_host);
    837819
    838     query.exec();
    839 
    840     query.prepare("SELECT playlistid FROM musicplaylist WHERE "
    841                   "name = :NAME AND hostname = :HOST ;");
    842     query.bindValue(":NAME", name.utf8());
    843     query.bindValue(":HOST", a_host);
    844 
    845     if (query.exec() && query.isActive() && query.size() > 0)
     820    int songcount = 0, playtime = 0, an_int;
     821    QStringList list = QStringList::split(",", raw_songlist);
     822    QStringList::iterator it = list.begin();
     823    for (; it != list.end(); it++)
    846824    {
    847         while(query.next())
     825        an_int = QString(*it).toInt();
     826        if (an_int != 0)
    848827        {
    849             //  If multiple rows with same name,
    850             //  make sure we get the last one
    851             playlistid = query.value(0).toInt();
     828            songcount++;
     829            if (an_int > 0)
     830            {
     831                query.prepare("SELECT length FROM music_songs WHERE song_id = :ID ;");
     832            }
     833            else
     834            {
     835                query.prepare("SELECT length FROM music_playlists WHERE playlist_id = :ID ;");
     836                an_int *= -1;
     837            }
     838            query.bindValue(":ID", an_int);
     839            query.exec();
     840            if (query.size() > 0)
     841            {
     842                query.next();
     843                playtime += query.value(0).toInt();
     844            }
    852845        }
    853846    }
     847
     848    bool save_host = ("default_playlist_storage" == a_name || "backup_playlist_storage" == a_name);
     849    if (playlistid > 0)
     850    {
     851        QString str_query = "UPDATE music_playlists SET playlist_songs = :LIST,"
     852                            " playlist_name = :NAME, songcount = :SONGCOUNT, length = :PLAYTIME";
     853        if (save_host)
     854            str_query += ", hostname = :HOSTNAME";
     855        str_query += " WHERE playlist_id = :ID ;";
     856
     857        query.prepare(str_query);
     858        query.bindValue(":ID", playlistid);
     859    }
    854860    else
    855861    {
    856         MythContext::DBError("playlist insert", query);
     862        QString str_query = "INSERT INTO music_playlists"
     863                            " (playlist_name, playlist_songs, songcount, length";
     864        if (save_host)
     865            str_query += ", hostname";
     866        str_query += ") VALUES(:NAME, :LIST, :SONGCOUNT, :PLAYTIME";
     867        if (save_host)
     868            str_query += ", :HOSTNAME";
     869        str_query += ");";
     870
     871        query.prepare(str_query);
    857872    }
     873    query.bindValue(":LIST", raw_songlist);
     874    query.bindValue(":NAME", a_name.utf8());
     875    query.bindValue(":SONGCOUNT", songcount);
     876    query.bindValue(":PLAYTIME", playtime);
     877    if (save_host)
     878        query.bindValue(":HOSTNAME", a_host);
     879
     880    if (!query.exec() || (playlistid < 1 && query.numRowsAffected() < 1))
     881    {
     882        MythContext::DBError("Problem saving playlist", query);
     883    }
     884
     885    if (playlistid < 1)
     886        playlistid = query.lastInsertId().toInt();
    858887}
    859888
    860889QString Playlist::removeDuplicateTracks(const QString &new_songlist)
    861890{
    862     raw_songlist = raw_songlist.remove(' ');
     891    raw_songlist.remove(' ');
    863892
    864893    QStringList curList = QStringList::split(",", raw_songlist);
    865894    QStringList newList = QStringList::split(",", new_songlist);
     
    10951124        if(a_list->hasChanged())
    10961125        {
    10971126            a_list->fillSonglistFromSongs();
    1098             a_list->savePlaylist(a_list->getName());
     1127            a_list->savePlaylist(a_list->getName(), my_host);
    10991128        }
    11001129    }
    1101    
    1102     active_playlist->savePlaylist("default_playlist_storage");
    1103     backup_playlist->savePlaylist("backup_playlist_storage");
     1130
     1131    active_playlist->savePlaylist("default_playlist_storage", my_host);
     1132    backup_playlist->savePlaylist("backup_playlist_storage", my_host);
    11041133}
    11051134
    11061135void PlaylistsContainer::createNewPlaylist(QString name)
    11071136{
    11081137    Playlist *new_list = new Playlist(all_available_music);
    11091138    new_list->setParent(this);
    1110     new_list->setName(name);
    1111    
     1139
    11121140    //  Need to touch the database to get persistent ID
    1113     new_list->saveNewPlaylist(my_host);
     1141    new_list->savePlaylist(name, my_host);
    11141142    new_list->Changed();
    11151143    all_other_playlists->append(new_list);
    11161144    //if(my_widget)
     
    11231151{
    11241152    Playlist *new_list = new Playlist(all_available_music);
    11251153    new_list->setParent(this);
    1126     new_list->setName(name);
     1154
    11271155    //  Need to touch the database to get persistent ID
    1128     new_list->saveNewPlaylist(my_host);
     1156    new_list->savePlaylist(name, my_host);
    11291157    new_list->Changed();
    11301158    all_other_playlists->append(new_list);
    11311159    active_playlist->copyTracks(new_list, false);
     
    11961224void PlaylistsContainer::renamePlaylist(int index, QString new_name)
    11971225{
    11981226    Playlist *list_to_rename = getPlaylist(index);
    1199     if(list_to_rename)
     1227    if (list_to_rename)
    12001228    {
    12011229        list_to_rename->setName(new_name);
    12021230        list_to_rename->Changed();
     
    12371265    }
    12381266
    12391267    MSqlQuery query(MSqlQuery::InitCon());
    1240     query.prepare("DELETE FROM musicplaylist WHERE playlistid = :ID ;");
     1268    query.prepare("DELETE FROM music_playlists WHERE playlist_id = :ID ;");
    12411269    query.bindValue(":ID", kill_me);
    12421270
    1243     if (query.exec() || query.size() < 1)
     1271    if (!query.exec() || query.numRowsAffected() < 1)
    12441272    {
    12451273        MythContext::DBError("playlist delete", query);
    12461274    }
     
    12611289        Playlist *a_list;
    12621290        for(a_list = all_other_playlists->last(); a_list; a_list = all_other_playlists->prev())
    12631291        {
    1264             if (a_list->getID() * -1 == index)
     1292            if (a_list->getID() == index)
    12651293            {
    12661294                return a_list->getName();   
    12671295            }
     
    15381566                level_down->computeSize(child_MB, child_sec);
    15391567                size_in_MB += child_MB;
    15401568                size_in_sec += child_sec;
    1541             }
     1569            }
    15421570        }
    15431571    }
    15441572}
  • mythmusic/mythmusic/cdrip.cpp

     
    104104    // which totally messes up the rest of the page.
    105105    artistedit->setMaximumWidth((int)(0.7 * screenwidth));
    106106
    107     fillComboBox(*artistedit, "artist");
    108 
     107    QStringList strlist = Metadata::fillFieldList("artist");
     108    artistedit->insertStringList(strlist);
     109   
    109110    QLabel *albuml = new QLabel(tr("Album: "), firstdiag);
    110111    albuml->setBackgroundOrigin(WindowOrigin);
    111112    albumedit = new MythLineEdit(firstdiag);
     
    114115    QLabel *genrelabel = new QLabel(tr("Genre: "), firstdiag);
    115116    genrelabel->setBackgroundOrigin(WindowOrigin);
    116117    genreedit = new MythComboBox(true, firstdiag);
    117     fillComboBox (*genreedit, "genre");
     118    strlist = Metadata::fillFieldList("genre");
     119    genreedit->insertStringList(strlist);
    118120
    119121
    120122    compilation = new MythCheckBox(firstdiag);
     
    196198
    197199                length = track->Length() / 1000;
    198200
    199                 QString title = track->Title();
    200                 newTune = isNewTune(artistname, albumname, title);
     201                QString title = track->Title();
     202                newTune = isNewTune(artistname, albumname, title);
    201203
    202                 if (newTune)
    203                 {
    204                     min = length / 60;
     204                if (newTune)
     205                {
     206                    min = length / 60;
    205207                    sec = length % 60;
    206208
    207                     table->setNumRows(row + 1);
    208                
    209                     table->setRowHeight(row, (int)(30 * hmult));
    210                    
    211                     label.sprintf("%d", trackno + 1);
    212                     table->setText(row, 0, label);
    213                    
    214                     table->setText(row, 1, track->Title());
    215                    
    216                     table->setText(row, 2, track->Artist());
    217                    
    218                     label.sprintf("%02d:%02d", min, sec);
    219                     table->setText(row, 3, label);
    220                
    221                     row++;
    222                 }
     209                    table->setNumRows(row + 1);
     210
     211                    table->setRowHeight(row, (int)(30 * hmult));
     212
     213                    label.sprintf("%d", trackno + 1);
     214                    table->setText(row, 0, label);
     215
     216                    table->setText(row, 1, track->Title());
     217
     218                    table->setText(row, 2, track->Artist());
     219
     220                    label.sprintf("%02d:%02d", min, sec);
     221                    table->setText(row, 3, label);
     222
     223                    row++;
     224                }
    223225                delete track;
    224226            }
    225227        }
     
    283285{
    284286    if (gContext->GetNumSetting("OnlyImportNewMusic",1))
    285287    {
    286         MSqlQuery query(MSqlQuery::InitCon()); 
    287         QString queryString("SELECT filename, artist, album, title, intid "
    288                             "FROM musicmetadata WHERE artist REGEXP \'");     
    289         QString token = artist;
    290         token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"), QString("."));
     288        MSqlQuery query(MSqlQuery::InitCon());
     289        QString queryString("SELECT filename, artist_name, album_name, name, song_id "
     290                            "FROM music_songs "
     291                            "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     292                            "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
     293                            "WHERE artist_name REGEXP \'");     
     294        QString token = artist;
     295        token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"), QString("."));
    291296     
    292         queryString += token + "\' AND " + "album REGEXP \'";
    293         token = album;
    294         token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"), QString("."));
    295         queryString += token + "\' AND " + "title    REGEXP \'";
    296         token = title;
    297         token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"), QString("."));
    298         queryString += token + "\' ORDER BY artist, album, title, intid, filename";     
    299         query.prepare(queryString);
    300        
    301         bool has_entries = true;     
    302         if (!query.exec() || !query.isActive())
    303         {
    304             MythContext::DBError("Search music database", query);
    305             has_entries = false;
    306         }
    307         if (query.numRowsAffected() > 0)
    308         {
    309             return false;
    310         }
     297        queryString += token + "\' AND " + "album_name REGEXP \'";
     298        token = album;
     299        token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"), QString("."));
     300        queryString += token + "\' AND " + "name    REGEXP \'";
     301        token = title;
     302        token.replace(QRegExp("(/|\\\\|:|\'|\\,|\\!|\\(|\\)|\"|\\?|\\|)"), QString("."));
     303        queryString += token + "\' ORDER BY artist_name, album_name, name, song_id, filename";     
     304        query.prepare(queryString);
     305       
     306        bool has_entries = true;     
     307        if (!query.exec() || !query.isActive())
     308        {
     309            MythContext::DBError("Search music database", query);
     310            has_entries = false;
     311        }
     312        if (query.numRowsAffected() > 0)
     313        {
     314            return false;
     315        }
    311316    }       
    312317    return true;
    313318}
     
    524529    delete decoder;
    525530}
    526531
    527 void Ripper::fillComboBox(MythComboBox &box, const QString &db_column)
    528 {
    529     QString querystr = QString("SELECT DISTINCT %1 FROM musicmetadata;")
    530                                .arg(db_column);
    531      
    532     MSqlQuery query(MSqlQuery::InitCon());
    533     query.exec(querystr);
    534    
    535     QValueList<QString> list;
    536    
    537     if (query.isActive() && query.size() > 0)
    538     {
    539         while (query.next())
    540         {
    541             list.push_front(query.value(0).toString());
    542         }
    543     }
    544    
    545     QStringList strlist(list);
    546    
    547     strlist.sort();
    548    
    549     box.insertStringList(strlist);
    550 }
    551 
    552532void Ripper::handleFileTokens(QString &filename, Metadata *track)
    553533{
    554534    QString original = filename;
  • mythmusic/mythmusic/smartplaylist.cpp

     
    1313using namespace std;
    1414
    1515#include "smartplaylist.h"
     16#include "metadata.h"
    1617
    1718#include <mythtv/mythcontext.h>
    1819#include <mythtv/dialogbox.h>
     
    3334static SmartPLField SmartPLFields[] =
    3435{
    3536    { "",              "",                               ftString,   0,    0,    0 },
    36     { "Artist",        "artist",                         ftString,   0,    0,    0 },
    37     { "Album",         "album",                          ftString,   0,    0,    0 },
    38     { "Title",         "title",                          ftString,   0,    0,    0 },
    39     { "Genre",         "genre",                          ftString,   0,    0,    0 },
    40     { "Year",          "year",                           ftNumeric,  1900, 2099, 2000 },
    41     { "Track No.",     "tracknum",                       ftNumeric,  0,    99,   0 },
    42     { "Rating",        "rating",                         ftNumeric,  0,    10,   0 },
    43     { "Play Count",    "playcount",                      ftNumeric,  0,    9999, 0 },
    44     { "Compilation",   "compilation",                    ftBoolean,  0,    0,    0 },
    45     { "Comp. Artist",  "compilation_artist",             ftString,   0,    0,    0 },
    46     { "Last Play",     "FROM_DAYS(TO_DAYS(lastplay))",   ftDate,     0,    0,    0 },
    47     { "Date Imported", "FROM_DAYS(TO_DAYS(date_added))", ftDate,     0,    0,    0 },
    48 };       
     37    { "Artist",        "music_artists.artist_name",      ftString,   0,    0,    0 },
     38    { "Album",         "music_songs.album_name",         ftString,   0,    0,    0 },
     39    { "Title",         "music_songs.name",               ftString,   0,    0,    0 },
     40    { "Genre",         "music_genres.genre",             ftString,   0,    0,    0 },
     41    { "Year",          "music_songs.year",               ftNumeric,  1900, 2099, 2000 },
     42    { "Track No.",     "music_songs.track",              ftNumeric,  0,    99,   0 },
     43    { "Rating",        "music_songs.rating",             ftNumeric,  0,    10,   0 },
     44    { "Play Count",    "music_songs.numplays",           ftNumeric,  0,    9999, 0 },
     45    { "Compilation",   "music_albums.compilation",       ftBoolean,  0,    0,    0 },
     46    { "Comp. Artist",  "music_comp_artists.artist_name", ftString,   0,    0,    0 },
     47    { "Last Play",     "FROM_DAYS(TO_DAYS(music_songs.lastplay))",
     48                                                         ftDate,     0,    0,    0 },
     49    { "Date Imported", "FROM_DAYS(TO_DAYS(music_songs.date_added))",
     50                                                         ftDate,     0,    0,    0 },
     51};
    4952
    5053struct SmartPLOperator
    5154{
     
    644647        value = searchDialog->getResult();
    645648        res = true;
    646649    }
    647    
     650
    648651    delete searchDialog;
    649    
    650     return res;     
    651 }
    652652
    653 void SmartPLCriteriaRow::fillSearchList(QString field)
    654 {
    655     searchList.clear();
    656    
    657     MSqlQuery query(MSqlQuery::InitCon());
    658     QString querystr;
    659     querystr = QString("SELECT DISTINCT %1 FROM musicmetadata ORDER BY %2").arg(field).arg(field);
    660        
    661     query.exec(querystr);
    662     if (query.isActive() && query.numRowsAffected())
    663     {
    664         while (query.next())
    665         {
    666             searchList << QString::fromUtf8(query.value(0).toString());
    667         }
    668     }         
     653    return res;
    669654}
    670    
     655
    671656void SmartPLCriteriaRow::searchArtist(MythRemoteLineEdit *editor)
    672657{
    673658    QString s;
    674    
    675     fillSearchList("artist");
    676    
     659
     660    searchList = Metadata::fillFieldList("artist");
     661
    677662    s = editor->text();
    678663    if (showList(tr("Select an Artist"), s))
    679664    {
     
    684669void SmartPLCriteriaRow::searchCompilationArtist(MythRemoteLineEdit *editor)
    685670{
    686671    QString s;
    687    
    688     fillSearchList("compilation_artist");
    689    
     672
     673    searchList = Metadata::fillFieldList("compilation_artist");
     674
    690675    s = editor->text();
    691676    if (showList(tr("Select a Compilation Artist"), s))
    692677    {
     
    697682void SmartPLCriteriaRow::searchAlbum(MythRemoteLineEdit *editor)
    698683{
    699684    QString s;
    700    
    701     fillSearchList("album");
    702    
     685
     686    searchList = Metadata::fillFieldList("album");
     687
    703688    s = editor->text();
    704689    if (showList(tr("Select an Album"), s))
    705690    {
     
    711696{
    712697    QString s;
    713698
    714     fillSearchList("genre");
     699    searchList = Metadata::fillFieldList("genre");
    715700
    716701    s = editor->text();
    717702    if (showList(tr("Select a Genre"), s))
     
    724709{
    725710    QString s;
    726711
    727     fillSearchList("title");
     712    searchList = Metadata::fillFieldList("title");
    728713
    729714    s = editor->text();
    730715    if (showList(tr("Select a Title"), s))
     
    815800    }
    816801   
    817802    MSqlQuery query(MSqlQuery::InitCon());
    818     query.prepare("INSERT INTO smartplaylistitem (smartplaylistid, field, operator,"
     803    query.prepare("INSERT INTO music_smartplaylist_items (smartplaylistid, field, operator,"
    819804                  " value1, value2)"
    820805                  "VALUES (:SMARTPLAYLISTID, :FIELD, :OPERATOR, :VALUE1, :VALUE2);");
    821806    query.bindValue(":SMARTPLAYLISTID", smartPlaylistID);
     
    11301115{
    11311116    bPlaylistIsValid = true;
    11321117   
    1133     QString sql = "select count(*) from musicmetadata ";
     1118    QString sql = "select count(*) from music_songs ";
    11341119    sql += getWhereClause();
    11351120   
    11361121    MSqlQuery query(MSqlQuery::InitCon());
     
    11771162   
    11781163    MSqlQuery query(MSqlQuery::InitCon());
    11791164    // insert new smartplaylist
    1180     query.prepare("INSERT INTO smartplaylist (name, categoryid, matchtype, orderby, limitto) "
     1165    query.prepare("INSERT INTO music_smartplaylists (name, categoryid, matchtype, orderby, limitto) "
    11811166                "VALUES (:NAME, :CATEGORYID, :MATCHTYPE, :ORDERBY, :LIMIT);");
    11821167    query.bindValue(":NAME", name.utf8());
    11831168    query.bindValue(":CATEGORYID", categoryid);
     
    11931178   
    11941179    // get smartplaylistid
    11951180    int ID;
    1196     query.prepare("SELECT smartplaylistid FROM smartplaylist "
     1181    query.prepare("SELECT smartplaylistid FROM music_smartplaylists "
    11971182                  "WHERE categoryid = :CATEGORYID AND name = :NAME;");
    11981183    query.bindValue(":CATEGORYID", categoryid);
    11991184    query.bindValue(":NAME", name.utf8());
     
    12521237    MSqlQuery query(MSqlQuery::InitCon());
    12531238    int ID;
    12541239   
    1255     query.prepare("SELECT smartplaylistid, name, categoryid, matchtype, orderby, limitto " 
    1256                   "FROM smartplaylist WHERE name = :NAME AND categoryid = :CATEGORYID;");
     1240    query.prepare("SELECT smartplaylistid, name, categoryid, matchtype, orderby, limitto "
     1241                  "FROM music_smartplaylists WHERE name = :NAME AND categoryid = :CATEGORYID;");
    12571242    query.bindValue(":NAME", name.utf8());
    12581243    query.bindValue(":CATEGORYID", categoryid);
    12591244    if (query.exec())
     
    12841269    SmartPLCriteriaRow *row;   
    12851270    uint rowCount;
    12861271   
    1287     query.prepare("SELECT field, operator, value1, value2 " 
    1288                   "FROM smartplaylistitem WHERE smartplaylistid = :ID "
     1272    query.prepare("SELECT field, operator, value1, value2 "
     1273                  "FROM music_smartplaylist_items WHERE smartplaylistid = :ID "
    12891274                  "ORDER BY smartplaylistitemid;");
    12901275    query.bindValue(":ID", ID);
    12911276    if (!query.exec())
     
    13921377    // insert new smartplaylistcategory
    13931378
    13941379    MSqlQuery query(MSqlQuery::InitCon());
    1395     query.prepare("INSERT INTO smartplaylistcategory (name) "
     1380    query.prepare("INSERT INTO music_smartplaylist_categories (name) "
    13961381                "VALUES (:NAME);");
    13971382    query.bindValue(":NAME", categoryEdit->text().utf8());
    13981383   
     
    14381423       
    14391424    // change the category     
    14401425    MSqlQuery query(MSqlQuery::InitCon());
    1441     query.prepare("UPDATE smartplaylistcategory SET name = :NEW_CATEGORY "
     1426    query.prepare("UPDATE music_smartplaylist_categories SET name = :NEW_CATEGORY "
    14421427                  "WHERE name = :OLD_CATEGORY;");
    14431428    query.bindValue(":OLD_CATEGORY", categoryCombo->currentText().utf8());
    14441429    query.bindValue(":NEW_CATEGORY", categoryEdit->text().utf8());
     
    14581443QString SmartPlaylistEditor::getSQL(QString fields)
    14591444{
    14601445    QString sql, whereClause, orderByClause, limitClause;
    1461    
    1462     sql = "SELECT " + fields + " FROM musicmetadata ";
     1446    sql = "SELECT " + fields + " FROM music_songs "
     1447          "LEFT JOIN music_artists ON music_songs.artist_id=music_artists.artist_id "
     1448          "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id "
     1449          "LEFT JOIN music_artists AS music_comp_artists ON music_albums.artist_id=music_comp_artists.artist_id "
     1450          "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id ";
     1451
    14631452    whereClause = getWhereClause();
    14641453    orderByClause = getOrderByClause();
    14651454    if (limitSpinEdit->value() > 0)
     
    15061495
    15071496void SmartPlaylistEditor::showResultsClicked(void)
    15081497{
    1509     QString sql = getSQL("intid, artist, album, title, genre, year, tracknum");
    1510    
     1498    QString sql = getSQL("song_id, music_artists.artist_name, album_name, name, genre, year, track");
     1499
    15111500    SmartPLResultViewer *resultViewer = new SmartPLResultViewer(gContext->GetMainWindow(), "resultviewer");
    15121501    resultViewer->setSQL(sql);
    15131502    resultViewer->exec();
     
    15351524    categoryCombo->clear();
    15361525    MSqlQuery query(MSqlQuery::InitCon());
    15371526
    1538     if (query.exec("SELECT name FROM smartplaylistcategory ORDER BY name;"))
     1527    if (query.exec("SELECT name FROM music_smartplaylist_categories ORDER BY name;"))
    15391528    {
    15401529        if (query.isActive() && query.numRowsAffected() > 0)
    15411530        {
     
    15631552   
    15641553    // get playlist ID
    15651554    int ID;
    1566     query.prepare("SELECT smartplaylistid FROM smartplaylist WHERE name = :NAME "
     1555    query.prepare("SELECT smartplaylistid FROM music_smartplaylists WHERE name = :NAME "
    15671556                  "AND categoryid = :CATEGORYID;");
    15681557    query.bindValue(":NAME", name.utf8());
    15691558    query.bindValue(":CATEGORYID", categoryid);
     
    15881577    }
    15891578   
    15901579    //delete smartplaylist items
    1591     query.prepare("DELETE FROM smartplaylistitem WHERE smartplaylistid = :ID;");
     1580    query.prepare("DELETE FROM music_smartplaylist_items WHERE smartplaylistid = :ID;");
    15921581    query.bindValue(":ID", ID);
    15931582    if (!query.exec())
    15941583        MythContext::DBError("Delete smartplaylist items", query);
    15951584
    15961585    //delete smartplaylist
    1597     query.prepare("DELETE FROM smartplaylist WHERE smartplaylistid = :ID;");
     1586    query.prepare("DELETE FROM music_smartplaylists WHERE smartplaylistid = :ID;");
    15981587    query.bindValue(":ID", ID);
    15991588    if (!query.exec())
    16001589        MythContext::DBError("Delete smartplaylist", query);
     
    16081597{
    16091598    int categoryid = SmartPlaylistEditor::lookupCategoryID(category);
    16101599    MSqlQuery query(MSqlQuery::InitCon());
    1611    
     1600
    16121601    //delete all smartplaylists with the selected category
    1613     query.prepare("SELECT name FROM smartplaylist "
     1602    query.prepare("SELECT name FROM music_smartplaylists "
    16141603                  "WHERE categoryid = :CATEGORYID;");
    16151604    query.bindValue(":CATEGORYID", categoryid);
    16161605    if (!query.exec())
     
    16291618    }
    16301619   
    16311620    // delete the category
    1632     query.prepare("DELETE FROM smartplaylistcategory WHERE categoryid = :ID;");
     1621    query.prepare("DELETE FROM music_smartplaylist_categories WHERE categoryid = :ID;");
    16331622    query.bindValue(":ID", categoryid);
    16341623    if (!query.exec())
    16351624        MythContext::DBError("Delete smartplaylist category", query);
     
    16391628
    16401629// static function to lookup the categoryid given its name
    16411630int SmartPlaylistEditor::lookupCategoryID(QString category)
    1642 {   
     1631{
    16431632    int ID;
    16441633    MSqlQuery query(MSqlQuery::InitCon());
    1645     query.prepare("SELECT categoryid FROM smartplaylistcategory "
     1634    query.prepare("SELECT categoryid FROM music_smartplaylist_categories "
    16461635                  "WHERE name = :CATEGORY;");
    16471636    query.bindValue(":CATEGORY", category.utf8());
    16481637
    16491638    if (query.exec())
    1650     {   
     1639    {
    16511640        if (query.isActive() && query.numRowsAffected() > 0)
    16521641        {
    16531642            query.first();
     
    20232012    categoryCombo->clear();
    20242013    MSqlQuery query(MSqlQuery::InitCon());
    20252014
    2026     if (query.exec("SELECT name FROM smartplaylistcategory ORDER BY name;"))
     2015    if (query.exec("SELECT name FROM music_smartplaylist_categories ORDER BY name;"))
    20272016    {
    20282017        if (query.isActive() && query.numRowsAffected() > 0)
    20292018        {
     
    20442033
    20452034    listbox->clear();
    20462035
    2047     MSqlQuery query(MSqlQuery::InitCon());   
    2048     query.prepare("SELECT name FROM smartplaylist WHERE categoryid = :CATEGORYID "
     2036    MSqlQuery query(MSqlQuery::InitCon());
     2037    query.prepare("SELECT name FROM music_smartplaylists WHERE categoryid = :CATEGORYID "
    20492038                  "ORDER BY name;");
    20502039    query.bindValue(":CATEGORYID", categoryid);
    20512040                   
  • mythmusic/mythmusic/metadata.h

     
    4242                format = lformat;
    4343            }
    4444
    45     Metadata(const Metadata &other) 
     45    Metadata(const Metadata &other)
    4646            {
     47                *this = other;
     48                changed = false;
     49                /*
    4750                filename = other.filename;
    4851                artist = other.artist;
    4952                compilation_artist = other.compilation_artist;
     
    6366                show = other.show;
    6467                changed = false;
    6568                format = other.format;
     69                */
    6670            }
    6771
    6872    Metadata& operator=(Metadata *rhs);
     
    125129    bool Compilation() { return compilation; }
    126130    void setCompilation(bool state) { compilation = state; formattedartist = formattedtitle = ""; }
    127131    bool determineIfCompilation(bool cd = false);
    128    
     132
    129133    bool isInDatabase(void);
    130134    void dumpToDatabase(void);
    131     void updateDatabase(void);
    132135    void setField(const QString &field, const QString &data);
    133136    void getField(const QString& field, QString *data);
    134     void fillData();
    135     void fillDataFromID();
    136137    void persist();
    137138    bool hasChanged(){return changed;}
    138139    int compare (Metadata *other);
     
    140141
    141142    static void SetStartdir(const QString &dir);
    142143
     144    static QStringList fillFieldList(QString field);
     145
    143146  private:
    144147    void setCompilationFormatting(bool cd = false);
    145148    QString formatReplaceSymbols(const QString &format);
  • mythmusic/mythmusic/editmetadata.cpp

     
    44#include "editmetadata.h"
    55#include "decoder.h"
    66#include "genres.h"
     7#include "metadata.h"
    78
    89EditMetadataDialog::EditMetadataDialog(Metadata *source_metadata,
    910                                 MythMainWindow *parent,
     
    357358        value = searchDialog->getResult();
    358359        res = true;
    359360    }
    360    
     361
    361362    delete searchDialog;
    362363    setActiveWindow();
    363    
    364     return res;     
    365 }
    366364
    367 void EditMetadataDialog::fillSearchList(QString field)
    368 {
    369     searchList.clear();
    370    
    371     QString querystr;
    372     querystr = QString("SELECT DISTINCT %1 FROM musicmetadata ORDER BY %2").arg(field).arg(field);
    373          
    374     MSqlQuery query(MSqlQuery::InitCon());
    375     query.exec(querystr);
    376 
    377     if (query.isActive() && query.size())
    378     {
    379         while (query.next())
    380         {
    381             searchList << QString::fromUtf8(query.value(0).toString());
    382         }
    383     }         
     365    return res;
    384366}
    385    
     367
    386368void EditMetadataDialog::searchArtist()
    387369{
    388370    QString s;
    389    
    390     fillSearchList("artist");
    391    
     371
     372    searchList = Metadata::fillFieldList("artist");
     373
    392374    s = m_metadata->Artist();
    393375    if (showList(tr("Select an Artist"), s))
    394376    {
     
    400382void EditMetadataDialog::searchCompilationArtist()
    401383{
    402384    QString s;
    403    
    404     fillSearchList("compilation_artist");
    405    
     385
     386    searchList = Metadata::fillFieldList("compilation_artist");
     387
    406388    s = m_metadata->CompilationArtist();
    407389    if (showList(tr("Select a Compilation Artist"), s))
    408390    {
     
    414396void EditMetadataDialog::searchAlbum()
    415397{
    416398    QString s;
    417    
    418     fillSearchList("album");
    419    
     399
     400    searchList = Metadata::fillFieldList("album");
     401
    420402    s = m_metadata->Album();
    421403    if (showList(tr("Select an Album"), s))
    422404    {
     
    430412    QString s;
    431413
    432414    // load genre list
     415    /*
    433416    searchList.clear();
    434417    for (int x = 0; x < genre_table_size; x++)
    435418        searchList.push_back(QString(genre_table[x]));
    436419    searchList.sort();
     420    */
     421    searchList = Metadata::fillFieldList("genre");
    437422
    438423    s = m_metadata->Genre();
    439424    if (showList(tr("Select a Genre"), s))
     
    491476{
    492477    cancelPopup();
    493478
    494     m_metadata->updateDatabase();
     479    m_metadata->dumpToDatabase();
    495480    *m_sourceMetadata = m_metadata;
    496481    done(1);
    497482}
  • mythmusic/mythmusic/smartplaylist.h

     
    7272    void value2ButtonClicked(void);
    7373 
    7474  private:
    75     void fillSearchList(QString field);
    7675    bool showList(QString caption, QString &value);
    7776    void searchGenre(MythRemoteLineEdit *editor);
    7877    void searchArtist(MythRemoteLineEdit *editor);
  • mythmusic/mythmusic/main.cpp

     
    9191    // We know that the filename will not contain :// as the SQL limits this
    9292    sqlfilename.remove(0, directory.length());
    9393    MSqlQuery query(MSqlQuery::InitCon());
    94     query.prepare("DELETE FROM musicmetadata WHERE "
     94    query.prepare("DELETE FROM music_songs WHERE "
    9595                  "filename = :NAME ;");
    9696    query.bindValue(":NAME", sqlfilename.utf8());
    9797    query.exec();
     
    110110        {
    111111            disk_meta->setID(db_meta->ID());
    112112            disk_meta->setRating(db_meta->Rating());
    113             disk_meta->updateDatabase();
     113            disk_meta->dumpToDatabase();
    114114        }
    115115
    116116        if (disk_meta)
     
    261261
    262262    MSqlQuery query(MSqlQuery::InitCon());
    263263    query.exec("SELECT filename, date_modified "
    264                "FROM musicmetadata "
     264               "FROM music_songs "
    265265               "WHERE filename NOT LIKE ('%://%')");
    266266
    267267    int counter = 0;
     
    561561
    562562
    563563    MSqlQuery count_query(MSqlQuery::InitCon());
    564     count_query.exec("SELECT COUNT(*) FROM musicmetadata;");
     564    count_query.exec("SELECT COUNT(*) FROM music_songs;");
    565565
    566566    bool musicdata_exists = false;
    567567    if (count_query.isActive())
  • mythmusic/mythmusic/editmetadata.h

     
    66
    77#include <mythtv/mythdialogs.h>
    88
    9 #include "metadata.h"
     9class Metadata;
    1010
    1111class UIPhoneEntry;
    1212
     
    4545    void checkClicked(bool state);
    4646  private:
    4747
    48     void fillSearchList(QString field);
    4948    bool showList(QString caption, QString &value);
    5049   
    5150    Metadata *m_metadata, *m_sourceMetadata ;
  • mythmusic/mythmusic/metaiomp4.cpp

     
    348348                                     genre,
    349349                                     year,
    350350                                     tracknum,
    351                                      length,
    352                                      0, 0, 0, "",
    353                                      compilation);
     351                                     length);
     352   
     353    retdata->setCompilation(compilation);
    354354
    355355    //retdata->setComposer(writer);
    356356    //retdata->setComment(comment);