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 555 by douglas, 2005-07-10T21:18:35-07:00 vs.
Revision 558 by douglas, 2005-07-17T00:50:52-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include <menes/c++/standard.hh>
7 > #include <menes/cxx/standard.hh>
8  
9   #include <menes/dbi/resultset.hpp>
10  
# Line 33 | Line 33 | _L<MediaFolder> Library::GetFolders(unsi
33          return folders;
34   }
35  
36 + unsigned Library::GetFoldersPages() const
37 + {
38 +        _R<dbi::Connection> connection(connector->Connect());
39 +        _R<dbi::ResultSet> count(connection->Execute(_B("SELECT count(DISTINCT root) FROM files WHERE live = TRUE")));
40 +        unsigned pages(0);
41 +
42 +        if (count->MoveNext())
43 +                pages = (count->Get<unsigned>(_B("count")) + 49) / 50;
44 +
45 +        connector->Release(connection);
46 +
47 +        return pages;
48 + }
49 +
50   _L<MediaFile> Library::GetFiles(const _L<By>& bys, const _L<cse::String>& items, unsigned page) const
51   {
52          if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() != items.GetSize())
# Line 66 | Line 80 | _L<MediaFile> Library::GetFiles(const _L
80          return files;
81   }
82  
83 + unsigned Library::GetFilesPages(const _L<By>& bys, const _L<cse::String>& items) const
84 + {
85 +        if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() != items.GetSize())
86 +                return 0;
87 +
88 +        _S<ios::String> statement_;
89 +
90 +        statement_ << _B("SELECT count(path) FROM files WHERE live = TRUE ");
91 +
92 +        _foreach (const _L<By>, by, bys)
93 +                statement_ << _B("AND ") << *by << _B(" = ?");
94 +
95 +        _R<dbi::Connection> connection(connector->Connect());
96 +        _R<dbi::Statement> statement(connection->Parse(statement_));
97 +
98 +        _foreach (const _L<cse::String>, item, items)
99 +                statement->Set(_index, *item);
100 +
101 +        _R<dbi::ResultSet> count(statement->Execute());
102 +        unsigned pages(0);
103 +
104 +        if (count->MoveNext())
105 +                pages = (count->Get<unsigned>(_B("count")) + 49) / 50;
106 +
107 +        connector->Release(connection);
108 +
109 +        return pages;
110 + }
111 +
112   _L<cse::String> Library::GetItems(_L<By> bys, _L<cse::String> items, unsigned page) const
113   {
114          if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize())
# Line 102 | Line 145 | _L<cse::String> Library::GetItems(_L<By>
145  
146          return items;
147   }
148 +
149 + unsigned Library::GetItemsPages(_L<By> bys, const _L<cse::String>& items) const
150 + {
151 +        if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize())
152 +                return 0;
153 +
154 +        _S<ios::String> statement_;
155 +        By by(bys.Last());
156 +
157 +        statement_ << _B("SELECT count(DISTINCT ") << by << _B(") FROM files WHERE live = TRUE");
158 +
159 +        bys.RemoveLast();
160 +
161 +        _foreach (const _L<By>, by_, bys)
162 +                statement_ << _B(" AND ") << *by_ << _B(" = ?");
163 +
164 +        _R<dbi::Connection> connection(connector->Connect());
165 +        _R<dbi::Statement> statement(connection->Parse(statement_));
166 +
167 +        _foreach (const _L<cse::String>, item, items)
168 +                statement->Set(_index, *item);
169 +
170 +        _R<dbi::ResultSet> count(statement->Execute());
171 +        unsigned pages(0);
172 +
173 +        if (count->MoveNext())
174 +                pages = (count->Get<unsigned>(_B("count")) + 49) / 50;
175 +
176 +        connector->Release(connection);
177 +
178 +        return pages;
179 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines