Ticket #2395: patch_use_new_db_structure.diff

File patch_use_new_db_structure.diff, 6.4 KB (added by bryan@…, 17 years ago)

Corrects the SQL

  • programs/mythbackend/httpstatus.cpp

     
    10451045
    10461046        if (query.isConnected())
    10471047        {
    1048             query.prepare("SELECT filename FROM musicmetadata WHERE intid = :KEY" );
     1048            query.prepare("SELECT filename FROM music_songs song WHERE song_id = :KEY" );
    10491049            query.bindValue(":KEY", nTrack );
    10501050            query.exec();
    10511051
  • programs/mythbackend/upnpcdsmusic.cpp

     
    5252
    5353static RootInfo g_RootNodes[] =
    5454{
    55     {   "All Music", 
     55    {   "All Music",
    5656        "*",
    57         "SELECT intid as id, "
    58           "title as name, "
     57        "SELECT song_id as id, "
     58          "name, "
    5959          "1 as children "
    60             "FROM musicmetadata "
     60            "FROM music_songs song "
    6161            "%1 "
    62             "ORDER BY title",
     62            "ORDER BY name",
    6363        "" },
    6464
    6565    {   "Recently Added",
    6666        "*",
    67         "SELECT intid id, "
    68           "title as name, "
     67        "SELECT song_id id, "
     68          "name, "
    6969          "1 as children "
    70             "FROM musicmetadata "
     70            "FROM music_songs song "
    7171            "%1 "
    72             "ORDER BY title",
    73         "WHERE (DATEDIFF( CURDATE(), date_added ) <= 30 ) " },
     72            "ORDER BY name",
     73        "WHERE (DATEDIFF( CURDATE(), date_modified ) <= 30 ) " },
    7474
    75     {   "By Album", 
    76         "album",
    77         "SELECT album as id, "
    78           "album as name, "
    79           "count( album ) as children "
    80             "FROM musicmetadata "
     75    {   "By Album",
     76        "album_id",
     77        "SELECT a.album_id as id, "
     78          "a.album_name as name, "
     79          "count( song.album_id ) as children "
     80            "FROM music_songs song join music_albums a on a.album_id = song.album_id "
    8181            "%1 "
    82             "GROUP BY album "
    83             "ORDER BY album",
    84         "WHERE album=:KEY" },
     82            "GROUP BY a.album_id "
     83            "ORDER BY a.album_name",
     84        "WHERE song.album_id=:KEY" },
    8585
     86
     87
    8688/*
    8789
    88     {   "By Artist", 
    89         "artist",
    90         "SELECT artist as id, "
    91           "artist as name, "
    92           "count( distinct album ) as children "
    93             "FROM musicmetadata "
     90    {   "By Artist",
     91        "artist_id",
     92        "SELECT a.artist_id as id, "
     93          "a.artist_name as name, "
     94          "count( distinct song.artist_id ) as children "
     95            "FROM music_songs song join music_artists a on a.artist_id = song.artist_id "
    9496            "%1 "
    95             "GROUP BY artist "
    96             "ORDER BY artist",
    97         "WHERE artist=:KEY" },
     97            "GROUP BY a.artist_id "
     98            "ORDER BY a.artist_name",
     99        "WHERE song.artist_id=:KEY" },
    98100*/
    99101/*
    100     {   "By Genre",
    101         "genre",
    102         "SELECT genre as id, "
     102{   "By Genre",
     103        "genre_id",
     104        "SELECT g.genre_id as id, "
    103105          "genre as name, "
    104           "count( distinct artist ) as children "
    105             "FROM musicmetadata "
     106          "count( distinct song.genre_id ) as children "
     107            "FROM music_songs song join music_genres g on g.genre_id = song.genre_id "
    106108            "%1 "
    107             "GROUP BY genre "
    108             "ORDER BY genre",
    109         "WHERE genre=:KEY" },
     109            "GROUP BY g.genre_id "
     110            "ORDER BY g.genre",
     111        "WHERE song.genre_id=:KEY" },
    110112
    111113*/
    112114};
     
    117119//
    118120/////////////////////////////////////////////////////////////////////////////
    119121
    120 #define SHARED_MUSIC_SQL "SELECT intid, artist, album, title, "          \
    121                                 "genre, year, tracknum, description, "   \
    122                                 "filename, length "                      \
    123                             "FROM musicmetadata "
     122#define SHARED_MUSIC_SQL "SELECT song.song_id as intid, artist.artist_name as artist, "         \
     123                             "album.album_name as album, song.name as title, "                  \
     124                             "genre.genre, song.year, song.track as tracknum, "                 \
     125                             "song.description, song.filename, song.length "                    \
     126                          "FROM music_songs song "                                              \
     127                             " join music_artists artist on artist.artist_id = song.artist_id " \
     128                             " join music_albums album on album.album_id = song.album_id "      \
     129                             " join music_genres genre on  genre.genre_id = song.genre_id "     \
     130                             " %1 "                                                                                                     
    124131
     132
    125133/////////////////////////////////////////////////////////////////////////////
    126134//
    127135/////////////////////////////////////////////////////////////////////////////
     
    596604        QString sSQL;
    597605       
    598606        if (sColumn == "*")
    599             sSQL = QString( "SELECT count( * ) FROM musicmetadata %1" ).arg( sWhere );
     607            sSQL = QString( "SELECT count( * ) FROM music_songs song %1" ).arg( sWhere );
    600608        else
    601             sSQL = QString( "SELECT count( DISTINCT %1 ) FROM musicmetadata" ).arg( sColumn );
     609            sSQL = QString( "SELECT count( DISTINCT %1 ) FROM music_songs song" ).arg( sColumn );
    602610
    603611        query.prepare( sSQL );
    604612        query.exec();
     
    630638        // Note: Tried to use Bind, however it would not allow me to use it
    631639        //       for column & table names
    632640
    633         QString sSQL = QString( "SELECT count( %1 ) FROM musicmetadata %2" )
     641        QString sSQL = QString( "SELECT count( %1 ) FROM music_songs song %2" )
    634642                          .arg( g_RootNodes[ nNodeIdx ].column )
    635643                          .arg( g_RootNodes[ nNodeIdx ].where );
    636644
     
    672680    if (query.isConnected())
    673681    {
    674682        QString sSQL = QString( SHARED_MUSIC_SQL
    675                                 "%1 LIMIT %2, %3" )
     683                                "LIMIT %2, %3" )
    676684                          .arg( g_RootNodes[ nNodeIdx ].where )
    677685                          .arg( pRequest->m_nStartingIndex    )
    678686                          .arg( pRequest->m_nRequestedCount   );