Commit 09373b6b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Invert is_present check to compare against 0 instead of 1

sqlite doesn't warrant a `true` boolean will have a value of 1, but
`false` will always be 0
parent 76cb9c06
......@@ -206,7 +206,7 @@ std::vector<MediaPtr> Album::tracks( SortingCriteria sort, bool desc ) const
// counter productive, to maintain a cache that respects all orderings.
std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
" INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media "
" WHERE att.album_id = ? AND med.is_present = 1";
" WHERE att.album_id = ? AND med.is_present != 0";
req += orderTracksBy( sort, desc );
return Media::fetchAll<IMedia>( m_ml, req, m_id );
}
......@@ -217,7 +217,7 @@ std::vector<MediaPtr> Album::tracks( GenrePtr genre, SortingCriteria sort, bool
return {};
std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
" INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media "
" WHERE att.album_id = ? AND med.is_present = 1"
" WHERE att.album_id = ? AND med.is_present != 0"
" AND genre_id = ?";
req += orderTracksBy( sort, desc );
return Media::fetchAll<IMedia>( m_ml, req, m_id, genre->id() );
......@@ -378,7 +378,7 @@ bool Album::createTriggers( sqlite::Connection* dbConnection )
" UPDATE " + policy::AlbumTable::Name + " SET is_present="
"(SELECT EXISTS("
"SELECT id_track FROM " + policy::AlbumTrackTable::Name +
" WHERE album_id=new.album_id AND is_present=1 LIMIT 1"
" WHERE album_id=new.album_id AND is_present != 0 LIMIT 1"
") )"
"WHERE id_album=new.album_id;"
" END";
......@@ -447,14 +447,14 @@ std::vector<AlbumPtr> Album::search( MediaLibraryPtr ml, const std::string& patt
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " WHERE id_album IN "
"(SELECT rowid FROM " + policy::AlbumTable::Name + "Fts WHERE " +
policy::AlbumTable::Name + "Fts MATCH '*' || ? || '*')"
"AND is_present = 1";
"AND is_present != 0";
return fetchAll<IAlbum>( ml, req, pattern );
}
std::vector<AlbumPtr> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc )
{
std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " alb "
"WHERE artist_id = ? AND is_present=1 ORDER BY ";
"WHERE artist_id = ? AND is_present != 0 ORDER BY ";
switch ( sort )
{
case SortingCriteria::Alpha:
......@@ -491,7 +491,7 @@ std::vector<AlbumPtr> Album::listAll( MediaLibraryPtr ml, SortingCriteria sort,
{
std::string req = "SELECT alb.* FROM " + policy::AlbumTable::Name + " alb "
"INNER JOIN " + policy::ArtistTable::Name + " art ON alb.artist_id = art.id_artist "
"WHERE alb.is_present = 1 "
"WHERE alb.is_present != 0 "
"ORDER BY art.name ";
if ( desc == true )
req += "DESC ";
......@@ -499,7 +499,7 @@ std::vector<AlbumPtr> Album::listAll( MediaLibraryPtr ml, SortingCriteria sort,
return fetchAll<IAlbum>( ml, req );
}
std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" WHERE is_present=1";
" WHERE is_present != 0";
req += orderBy( sort, desc );
return fetchAll<IAlbum>( ml, req );
}
......
......@@ -93,7 +93,7 @@ std::vector<MediaPtr> Artist::media( SortingCriteria sort, bool desc ) const
{
std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"INNER JOIN MediaArtistRelation mar ON mar.media_id = med.id_media "
"WHERE mar.artist_id = ? AND med.is_present = 1 ORDER BY ";
"WHERE mar.artist_id = ? AND med.is_present != 0 ORDER BY ";
switch ( sort )
{
case SortingCriteria::Duration:
......@@ -228,7 +228,7 @@ bool Artist::createTriggers( sqlite::Connection* dbConnection )
" UPDATE " + policy::ArtistTable::Name + " SET is_present="
"(SELECT EXISTS("
"SELECT id_album FROM " + policy::AlbumTable::Name +
" WHERE artist_id=new.artist_id AND is_present=1 LIMIT 1"
" WHERE artist_id=new.artist_id AND is_present != 0 LIMIT 1"
") )"
"WHERE id_artist=new.artist_id;"
" END";
......@@ -298,7 +298,7 @@ std::vector<ArtistPtr> Artist::search( MediaLibraryPtr ml, const std::string& na
std::vector<ArtistPtr> Artist::listAll(MediaLibraryPtr ml, SortingCriteria sort, bool desc)
{
std::string req = "SELECT * FROM " + policy::ArtistTable::Name +
" WHERE nb_albums > 0 AND is_present = 1 ORDER BY ";
" WHERE nb_albums > 0 AND is_present != 0 ORDER BY ";
switch ( sort )
{
default:
......
......@@ -319,14 +319,14 @@ std::shared_ptr<File> File::fromExternalMrl( MediaLibraryPtr ml, const std::stri
std::vector<std::shared_ptr<File>> File::fetchUnparsed( MediaLibraryPtr ml )
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE parser_step != ? AND is_present = 1 AND folder_id IS NOT NULL AND parser_retries < 3";
+ " WHERE parser_step != ? AND is_present != 0 AND folder_id IS NOT NULL AND parser_retries < 3";
return File::fetchAll<File>( ml, req, parser::Task::ParserStep::Completed );
}
void File::resetRetryCount( MediaLibraryPtr ml )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET "
"parser_retries = 0 WHERE parser_step != ? AND is_present = 1 AND folder_id IS NOT NULL";
"parser_retries = 0 WHERE parser_step != ? AND is_present != 0 AND folder_id IS NOT NULL";
sqlite::Tools::executeUpdate( ml->getConn(), req, parser::Task::ParserStep::Completed );
}
......
......@@ -285,7 +285,7 @@ std::vector<std::shared_ptr<File>> Folder::files()
std::vector<std::shared_ptr<Folder>> Folder::folders()
{
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name
+ " WHERE parent_id = ? AND is_blacklisted = 0 AND is_present = 1";
+ " WHERE parent_id = ? AND is_blacklisted = 0 AND is_present != 0";
return DatabaseHelpers::fetchAll<Folder>( m_ml, req, m_id );
}
......@@ -324,7 +324,7 @@ std::vector<std::shared_ptr<Folder>> Folder::fetchRootFolders( MediaLibraryPtr m
" LEFT JOIN ExcludedEntryFolder"
" ON " + policy::FolderTable::Name + ".id_folder = ExcludedEntryFolder.folder_id"
" WHERE ExcludedEntryFolder.folder_id IS NULL AND"
" parent_id IS NULL AND is_blacklisted = 0 AND is_present = 1";
" parent_id IS NULL AND is_blacklisted = 0 AND is_present != 0";
return DatabaseHelpers::fetchAll<Folder>( ml, req );
}
......
......@@ -435,7 +435,8 @@ std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, Sor
req += " DESC";
return fetchAll<IMedia>( ml, req, type, File::Type::Main );
}
req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? AND is_present = 1 ORDER BY ";
req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? AND "
"is_present != 0 ORDER BY ";
switch ( sort )
{
case SortingCriteria::Duration:
......@@ -557,7 +558,7 @@ bool Media::createTriggers( sqlite::Connection* connection )
" UPDATE " + policy::MediaTable::Name + " SET is_present="
"(SELECT EXISTS("
"SELECT id_file FROM " + policy::FileTable::Name +
" WHERE media_id=new.media_id AND is_present=1 LIMIT 1"
" WHERE media_id=new.media_id AND is_present != 0 LIMIT 1"
") )"
"WHERE id_media=new.media_id;"
" END;";
......
......@@ -547,7 +547,7 @@ ArtistPtr MediaLibrary::artist( int64_t id ) const
ArtistPtr MediaLibrary::artist( const std::string& name )
{
static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name
+ " WHERE name = ? AND is_present = 1";
+ " WHERE name = ? AND is_present != 0";
return Artist::fetch( this, req, name );
}
......
......@@ -120,7 +120,7 @@ std::vector<MediaPtr> Playlist::media() const
{
static const std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m "
"LEFT JOIN PlaylistMediaRelation pmr ON pmr.media_id = m.id_media "
"WHERE pmr.playlist_id = ? AND m.is_present = 1 "
"WHERE pmr.playlist_id = ? AND m.is_present != 0 "
"ORDER BY pmr.position";
return Media::fetchAll<IMedia>( m_ml, req, m_id );
}
......
......@@ -51,7 +51,7 @@ std::shared_ptr<Media> MediaLibraryTester::media( int64_t id )
std::shared_ptr<Folder> MediaLibraryTester::folder( const std::string& mrl )
{
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name +
" WHERE is_blacklisted = 0 AND is_present = 1";
" WHERE is_blacklisted = 0 AND is_present != 0";
auto folders = Folder::DatabaseHelpers::fetchAll<Folder>( this, req );
for ( auto &f : folders )
{
......@@ -137,7 +137,7 @@ std::shared_ptr<AlbumTrack> MediaLibraryTester::albumTrack( int64_t id )
std::vector<MediaPtr> MediaLibraryTester::files()
{
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE is_present = 1";
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE is_present != 0";
return Media::fetchAll<IMedia>( this, req );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment