ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/Library.cpp
(Generate patch)

Comparing DecentralizedMedia/Library.cpp (file contents):
Revision 549 by douglas, 2005-07-04T21:28:02-07:00 vs.
Revision 554 by douglas, 2005-07-10T04:22:54-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include <menes/standard.hh>
7 > #include <menes/c++/standard.hh>
8  
9   #include <menes/dbi/resultset.hpp>
10  
# Line 15 | Line 15 | Library::Library(const _R<dbi::Connectio
15          connection->Execute(_B("UPDATE files SET live = FALSE"));
16   }
17  
18 < _L<cse::String> Library::GetArtists() const
18 > _L<MediaFolder> Library::GetFolders(unsigned page) const
19   {
20 <        _R<dbi::ResultSet> artists_(connection->Execute(_B("SELECT DISTINCT artist FROM files WHERE live = TRUE")));
21 <        _L<cse::String> artists;
20 >        _R<dbi::ResultSet> roots(connection->Parse(_B("SELECT DISTINCT root FROM files WHERE live = TRUE ORDER By root LIMIT 50 OFFSET ?"))->Execute(page * 50));
21 >        _L<MediaFolder> folders;
22  
23 <        while (artists_->MoveNext())
24 <                artists.InsertLast(artists_->GetString(_B("artist")));
23 >        while (roots->MoveNext())
24 >                folders.InsertLast(GetFolder(roots->GetString(_B("root"))));
25  
26 <        return artists;
26 >        return folders;
27   }
28  
29 < _L<cse::String> Library::GetTitles() const
29 > _L<MediaFile> Library::GetFiles(const _L<By>& bys, const _L<cse::String>& items, unsigned page) const
30   {
31 <        _R<dbi::ResultSet> titles_(connection->Execute(_B("SELECT DISTINCT title FROM files WHERE live = TRUE")));
32 <        _L<cse::String> titles;
31 >        if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() != items.GetSize())
32 >                return _L<MediaFile>();
33  
34 <        while (titles_->MoveNext())
35 <                titles.InsertLast(titles_->GetString(_B("title")));
34 >        _S<ios::String> statement_;
35  
36 <        return titles;
38 < }
36 >        statement_ << _B("SELECT path FROM files WHERE live = TRUE ");
37  
38 < _L<cse::String> Library::GetAlbums() const
39 < {
42 <        _R<dbi::ResultSet> albums_(connection->Execute(_B("SELECT DISTINCT album FROM files WHERE live = TRUE")));
43 <        _L<cse::String> albums;
38 >        _foreach (const _L<By>, by, bys)
39 >                statement_ << _B("AND ") << *by << _B(" = ? ");
40  
41 <        while (albums_->MoveNext())
46 <                albums.InsertLast(albums_->GetString(_B("album")));
41 >        statement_ << _B("ORDER BY path LIMIT 50 OFFSET ?");
42  
43 <        return albums;
49 < }
43 >        _R<dbi::Statement> statement(connection->Parse(statement_));
44  
45 < _L<cse::String> Library::GetGenres() const
46 < {
47 <        _R<dbi::ResultSet> genres_(connection->Execute(_B("SELECT DISTINCT album FROM files WHERE live = TRUE")));
48 <        _L<cse::String> genres;
45 >        _foreach (const _L<cse::String>, item, items)
46 >                statement->Set(_index, *item);
47 >
48 >        statement->Set(items.GetSize(), page * 50);
49 >
50 >        _R<dbi::ResultSet> paths(statement->Execute());
51 >        _L<MediaFile> files;
52  
53 <        while (genres_->MoveNext())
54 <                genres.InsertLast(genres_->GetString(_B("genre")));
53 >        while (paths->MoveNext())
54 >                files.InsertLast(GetFile(paths->GetString(_B("path"))));
55  
56 <        return genres;
56 >        return files;
57   }
58  
59 < _L<MediaFolder> Library::GetFolders() const
59 > _L<cse::String> Library::GetItems(_L<By> bys, _L<cse::String> items, unsigned page) const
60   {
61 <        _R<dbi::ResultSet> roots(connection->Execute(_B("SELECT DISTINCT root FROM files WHERE live = TRUE")));
62 <        _L<MediaFolder> folders;
61 >        if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize())
62 >                return _L<cse::String>();
63  
64 <        while (roots->MoveNext())
65 <                folders.InsertLast(MediaFolder(connection, roots->GetString(_B("root"))));
64 >        _S<ios::String> statement_;
65 >        By by(bys.Last());
66  
67 <        return folders;
67 >        statement_ << _B("SELECT DISTINCT ") << by << _B(" FROM files WHERE live = TRUE ");
68 >
69 >        bys.RemoveLast();
70 >
71 >        _foreach (const _L<By>, by_, bys)
72 >                statement_ << _B("AND ") << *by_ << _B(" = ? ");
73 >
74 >        statement_ << _B("ORDER BY ") << by << _B(" LIMIT 50 OFFSET ?");
75 >
76 >        _R<dbi::Statement> statement(connection->Parse(statement_));
77 >
78 >        _foreach (const _L<cse::String>, item, items)
79 >                statement->Set(_index, *item);
80 >
81 >        statement->Set(items.GetSize(), page * 50);
82 >
83 >        _R<dbi::ResultSet> items_(statement->Execute());
84 >        
85 >        items.Clear();
86 >
87 >        while (items_->MoveNext())
88 >                items.InsertLast(items_->GetString(lexical_cast<cse::String>(by)));
89 >
90 >        return items;
91   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines