// -------------------------------------------------------------------------------- // int guDbRadios::DelRadioStations( int source, const wxArrayInt &radioids ) { wxString query; if( radioids.Count() ) { query = wxString::Format( wxT( "DELETE FROM radiostations WHERE radiostation_source = %i AND " ), source ); query += ArrayToFilter( radioids, wxT( "radiostation_genreid" ) ); return ExecuteUpdate( query ); } return 0; }
// -------------------------------------------------------------------------------- // void guDbRadios::GetRadioGenres( const int source, guListItems * radiogenres, bool AllowFilter, wxArrayInt * radioflags ) { wxString query; wxSQLite3ResultSet dbRes; //if( !AllowFilter || !GetRadioFiltersCount() ) if( !AllowFilter || ( !m_RaTeFilters.Count() && !m_RaLaFilters.Count() ) ) { query = wxT( "SELECT radiogenre_id, radiogenre_name, radiogenre_flags FROM radiogenres " ); query += wxString::Format( wxT( "WHERE radiogenre_source = %i " ), source ); query += wxT( "ORDER BY radiogenre_name COLLATE NOCASE;" ); } else { query = wxT( "SELECT DISTINCT radiogenre_id, radiogenre_name, radiogenre_flags FROM radiogenres, radiostations " ); query += wxString::Format( wxT( "WHERE radiogenre_source = %i " ), source ); query += wxT( "AND radiogenre_id = radiostation_genreid " ); if( m_RaTeFilters.Count() ) { query += wxT( " AND " ); query += RadioFiltersSQL(); } if( m_RaLaFilters.Count() ) { query += wxT( " AND radiostation_scid IN ( SELECT DISTINCT radiosetlabel_stationid FROM radiosetlabels WHERE " ); query += ArrayToFilter( m_RaLaFilters, wxT( "radiosetlabel_labelid" ) ); query += wxT( " )" ); } query += wxT( " ORDER BY radiogenre_name COLLATE NOCASE;" ); } //guLogMessage( query ); dbRes = ExecuteQuery( query ); while( dbRes.NextRow() ) { radiogenres->Add( new guListItem( dbRes.GetInt( 0 ), dbRes.GetString( 1 ) ) ); if( radioflags ) radioflags->Add( dbRes.GetInt( 2 ) ); } dbRes.Finalize(); }
// -------------------------------------------------------------------------------- // void guDbRadios::GetRadioGenresList( const int source, const wxArrayInt &ids, guListItems * listitems, wxArrayInt * radioflags ) { wxString query; wxSQLite3ResultSet dbRes; if( ids.Count() ) { query = wxT( "SELECT radiogenre_id, radiogenre_name, radiogenre_flags FROM radiogenres WHERE " ); query += wxString::Format( wxT( "radiogenre_source = %i AND " ), source ); query += ArrayToFilter( ids, wxT( "radiogenre_id" ) ); query += wxT( " ORDER BY radiogenre_name COLLATE NOCASE;" ); //guLogMessage( query ); dbRes = ExecuteQuery( query ); while( dbRes.NextRow() ) { listitems->Add( new guListItem( dbRes.GetInt( 0 ), dbRes.GetString( 1 ) ) ); if( radioflags ) radioflags->Add( dbRes.GetInt( 2 ) ); } dbRes.Finalize(); } }
// -------------------------------------------------------------------------------- // int guDbRadios::GetRadioStations( guRadioStations * Stations ) { wxString query; wxString querydb; wxString subquery; wxSQLite3ResultSet dbRes; guRadioStation * Station; if( !GetRadioFiltersCount() ) { query = wxT( "SELECT DISTINCT radiostation_name, radiostation_id, radiostation_scid, " \ "radiostation_source, radiostation_genreid, radiostation_link, radiostation_type, " \ "radiostation_br, radiostation_lc, radiostation_ct " \ "FROM radiostations WHERE " ); query += wxString::Format( wxT( "radiostation_source = %u " ), m_RadioSource ); query += wxT( "GROUP BY radiostation_name, radiostation_br " ); } else { if( m_RadioSource == guRADIO_SOURCE_USER ) { //SELECT * FROM radiostations, radiosetlabels WHERE radiosetlabel_stationid = radiostation_id AND radiosetlabel_labelid IN ( 1 ) query = wxT( "SELECT DISTINCT radiostation_name, radiostation_id, radiostation_scid, radiostation_source, radiostation_genreid, radiostation_link, radiostation_type, radiostation_br, radiostation_lc, radiostation_ct " ); querydb = wxT( "FROM radiostations " ); //else wxString subquery = wxEmptyString; if( m_RaLaFilters.Count() ) { querydb += wxT( ", radiosetlabels " ); subquery += wxT( "WHERE radiostation_scid = radiosetlabel_stationid AND radiostation_source = 1" ); subquery += wxT( " AND " ) + ArrayToFilter( m_RaLaFilters, wxT( "radiosetlabel_labelid" ) ); } else { subquery += wxT( "WHERE radiostation_source = 1 " ); } if( m_RaTeFilters.Count() ) { //querydb += wxT( ", radiogenres " ); //subquery += wxT( "AND radiostation_genreid = radiogenre_id " ); subquery += wxT( "AND " ) + RadioFiltersSQL(); } subquery += wxT( "GROUP BY radiostation_name, radiostation_br " ); query = query + querydb + subquery; } else { //SELECT * FROM radiostations, radiosetlabels WHERE radiosetlabel_stationid = radiostation_id AND radiosetlabel_labelid IN ( 1 ) query = wxT( "SELECT DISTINCT radiostation_name, radiostation_id, radiostation_scid, radiostation_source, " \ "radiostation_genreid, radiostation_link, radiostation_type, radiostation_br, radiostation_lc, radiostation_ct " \ "FROM radiostations, radiogenres" ); //else wxString subquery = wxEmptyString; if( m_RaLaFilters.Count() ) { query += wxT( ", radiosetlabels WHERE radiostation_genreid = radiogenre_id AND radiostation_scid = radiosetlabel_stationid AND " ); subquery += ArrayToFilter( m_RaLaFilters, wxT( "radiosetlabel_labelid" ) ); } else { query += wxT( " WHERE radiostation_genreid = radiogenre_id " ); } subquery += wxString::Format( wxT( " AND radiostation_source = %i " ), m_RadioSource ); if( m_RaGeFilters.Count() ) { subquery += wxT( " AND " ) + ArrayToFilter( m_RaGeFilters, wxT( "radiostation_genreid" ) ); } if( m_RaTeFilters.Count() ) { subquery += wxT( " AND " ) + RadioFiltersSQL(); } if( !subquery.IsEmpty() ) { query = query + subquery; } query += wxT( "GROUP BY radiostation_name, radiostation_br " ); } } query += wxT( " ORDER BY " ); if( m_StationsOrder == guRADIOSTATIONS_ORDER_NAME ) query += wxT( "radiostation_name COLLATE NOCASE" ); else if( m_StationsOrder == guRADIOSTATIONS_ORDER_BITRATE ) query += wxT( "radiostation_br" ); else if( m_StationsOrder == guRADIOSTATIONS_ORDER_LISTENERS ) query += wxT( "radiostation_lc" ); else if( m_StationsOrder == guRADIOSTATIONS_ORDER_TYPE ) query += wxT( "radiostation_type" ); else //if( m_StationsOrder == guRADIOSTATIONS_COLUMN_NOWPLAYING ) query += wxT( "radiostation_ct" ); if( m_StationsOrderDesc ) query += wxT( " DESC;" ); //guLogMessage( wxT( "GetRadioStations\n%s" ), query.c_str() ); dbRes = ExecuteQuery( query ); while( dbRes.NextRow() ) { Station = new guRadioStation(); Station->m_Name = dbRes.GetString( 0 ); Station->m_Id = dbRes.GetInt( 1 ); Station->m_SCId = dbRes.GetInt( 2 ); Station->m_Source = dbRes.GetInt( 3 ); Station->m_GenreId = dbRes.GetInt( 4 ); Station->m_Link = dbRes.GetString( 5 ); Station->m_Type = dbRes.GetString( 6 ); Station->m_BitRate = dbRes.GetInt( 7 ); Station->m_Listeners = dbRes.GetInt( 8 ); Station->m_NowPlaying = dbRes.GetString( 9 ); Stations->Add( Station ); } dbRes.Finalize(); return Stations->Count(); }
// -------------------------------------------------------------------------------- // guLibCleanThread::ExitCode guLibCleanThread::Entry() { wxString query; wxArrayInt SongsToDel; wxArrayInt CoversToDel; wxSQLite3ResultSet dbRes; wxString FileName; wxArrayString LibPaths = m_MediaViewer->GetPaths(); if( !TestDestroy() ) { CheckSymLinks( LibPaths ); query = wxT( "SELECT DISTINCT song_id, song_filename, song_path FROM songs " ); dbRes = m_Db->ExecuteQuery( query ); while( !TestDestroy() && dbRes.NextRow() ) { FileName = dbRes.GetString( 2 ) + dbRes.GetString( 1 ); //guLogMessage( wxT( "Checking %s" ), FileName.c_str() ); if( !wxFileExists( FileName ) || !CheckFileLibPath( LibPaths, FileName ) ) { SongsToDel.Add( dbRes.GetInt( 0 ) ); } } dbRes.Finalize(); if( !TestDestroy() ) { query = wxT( "SELECT DISTINCT cover_id, cover_path FROM covers;" ); dbRes = m_Db->ExecuteQuery( query ); while( !TestDestroy() && dbRes.NextRow() ) { if( !wxFileExists( dbRes.GetString( 1 ) ) ) { CoversToDel.Add( dbRes.GetInt( 0 ) ); } } dbRes.Finalize(); if( !TestDestroy() ) { wxArrayString Queries; //m_Db->CleanItems( SongsToDel, CoversToDel ); if( SongsToDel.Count() ) { Queries.Add( wxT( "DELETE FROM songs WHERE " ) + ArrayToFilter( SongsToDel, wxT( "song_id" ) ) ); } if( CoversToDel.Count() ) { Queries.Add( wxT( "DELETE FROM covers WHERE " ) + ArrayToFilter( CoversToDel, wxT( "cover_id" ) ) ); } // Delete all posible orphan entries Queries.Add( wxT( "DELETE FROM covers WHERE cover_id NOT IN ( SELECT DISTINCT song_coverid FROM songs );" ) ); Queries.Add( wxT( "DELETE FROM plsets WHERE plset_type = 0 AND plset_songid > 0 AND plset_songid NOT IN ( SELECT DISTINCT song_id FROM songs );" ) ); Queries.Add( wxT( "DELETE FROM settags WHERE settag_songid NOT IN ( SELECT DISTINCT song_id FROM songs );" ) ); int Index; int Count = Queries.Count(); for( Index = 0; Index < Count; Index++ ) { if( TestDestroy() ) break; //guLogMessage( wxT( "Executing: '%s'" ), Queries[ Index ].c_str() ); m_Db->ExecuteUpdate( Queries[ Index ] ); } //m_Db->LoadCache(); } } } return 0; }