--- DecentralizedMedia/Library.cpp 2005/07/05 06:37:40 550 +++ DecentralizedMedia/Library.cpp 2005/07/10 11:22:54 554 @@ -4,7 +4,7 @@ // // $Id$ -#include +#include #include @@ -15,57 +15,77 @@ Library::Library(const _RExecute(_B("UPDATE files SET live = FALSE")); } -_L Library::GetArtists() const +_L Library::GetFolders(unsigned page) const { - _R artists_(connection->Execute(_B("SELECT DISTINCT artist FROM files WHERE live = TRUE ORDER BY artist"))); - _L artists; + _R roots(connection->Parse(_B("SELECT DISTINCT root FROM files WHERE live = TRUE ORDER By root LIMIT 50 OFFSET ?"))->Execute(page * 50)); + _L folders; - while (artists_->MoveNext()) - artists.InsertLast(artists_->GetString(_B("artist"))); + while (roots->MoveNext()) + folders.InsertLast(GetFolder(roots->GetString(_B("root")))); - return artists; + return folders; } -_L Library::GetTitles() const +_L Library::GetFiles(const _L& bys, const _L& items, unsigned page) const { - _R titles_(connection->Execute(_B("SELECT DISTINCT title FROM files WHERE live = TRUE ORDER BY title"))); - _L titles; + if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() != items.GetSize()) + return _L(); - while (titles_->MoveNext()) - titles.InsertLast(titles_->GetString(_B("title"))); + _S statement_; - return titles; -} + statement_ << _B("SELECT path FROM files WHERE live = TRUE "); -_L Library::GetAlbums() const -{ - _R albums_(connection->Execute(_B("SELECT DISTINCT album FROM files WHERE live = TRUE ORDER BY album"))); - _L albums; + _foreach (const _L, by, bys) + statement_ << _B("AND ") << *by << _B(" = ? "); - while (albums_->MoveNext()) - albums.InsertLast(albums_->GetString(_B("album"))); + statement_ << _B("ORDER BY path LIMIT 50 OFFSET ?"); - return albums; -} + _R statement(connection->Parse(statement_)); -_L Library::GetGenres() const -{ - _R genres_(connection->Execute(_B("SELECT DISTINCT genre FROM files WHERE live = TRUE ORDER BY genre"))); - _L genres; + _foreach (const _L, item, items) + statement->Set(_index, *item); + + statement->Set(items.GetSize(), page * 50); + + _R paths(statement->Execute()); + _L files; - while (genres_->MoveNext()) - genres.InsertLast(genres_->GetString(_B("genre"))); + while (paths->MoveNext()) + files.InsertLast(GetFile(paths->GetString(_B("path")))); - return genres; + return files; } -_L Library::GetFolders() const +_L Library::GetItems(_L bys, _L items, unsigned page) const { - _R roots(connection->Execute(_B("SELECT DISTINCT root FROM files WHERE live = TRUE ORDER By root"))); - _L folders; + if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize()) + return _L(); - while (roots->MoveNext()) - folders.InsertLast(MediaFolder(connection, roots->GetString(_B("root")))); + _S statement_; + By by(bys.Last()); - return folders; + statement_ << _B("SELECT DISTINCT ") << by << _B(" FROM files WHERE live = TRUE "); + + bys.RemoveLast(); + + _foreach (const _L, by_, bys) + statement_ << _B("AND ") << *by_ << _B(" = ? "); + + statement_ << _B("ORDER BY ") << by << _B(" LIMIT 50 OFFSET ?"); + + _R statement(connection->Parse(statement_)); + + _foreach (const _L, item, items) + statement->Set(_index, *item); + + statement->Set(items.GetSize(), page * 50); + + _R items_(statement->Execute()); + + items.Clear(); + + while (items_->MoveNext()) + items.InsertLast(items_->GetString(lexical_cast(by))); + + return items; }