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 553 by douglas, 2005-07-07T04:24:27-07:00 vs.
Revision 554 by douglas, 2005-07-10T04:22:54-07:00

# Line 15 | Line 15 | Library::Library(const _R<dbi::Connectio
15          connection->Execute(_B("UPDATE files SET live = FALSE"));
16   }
17  
18 < _L<MediaFolder> Library::GetFolders() const
18 > _L<MediaFolder> Library::GetFolders(unsigned page) const
19   {
20 <        _R<dbi::ResultSet> roots(connection->Execute(_B("SELECT DISTINCT root FROM files WHERE live = TRUE ORDER By root")));
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 (roots->MoveNext())
# Line 26 | Line 26 | _L<MediaFolder> Library::GetFolders() co
26          return folders;
27   }
28  
29 < _L<MediaFile> Library::GetFiles(const _L<By>& bys, const _L<cse::String>& items) const
29 > _L<MediaFile> Library::GetFiles(const _L<By>& bys, const _L<cse::String>& items, unsigned page) const
30   {
31          if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() != items.GetSize())
32                  return _L<MediaFile>();
# Line 36 | Line 36 | _L<MediaFile> Library::GetFiles(const _L
36          statement_ << _B("SELECT path FROM files WHERE live = TRUE ");
37  
38          _foreach (const _L<By>, by, bys)
39 <                statement_ << _B("AND ") << by << _B(" = ? ");
39 >                statement_ << _B("AND ") << *by << _B(" = ? ");
40  
41 <        _rforeach (const _L<By>, by, bys)
42 <                statement_ << _B(by + 1 == _set.End() ? "ORDER BY " : ", ") << *by;
41 >        statement_ << _B("ORDER BY path LIMIT 50 OFFSET ?");
42  
43          _R<dbi::Statement> statement(connection->Parse(statement_));
44  
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  
# Line 55 | Line 56 | _L<MediaFile> Library::GetFiles(const _L
56          return files;
57   }
58  
59 < _L<cse::String> Library::GetItems(_L<By> bys, _L<cse::String> items) const
59 > _L<cse::String> Library::GetItems(_L<By> bys, _L<cse::String> items, unsigned page) const
60   {
61          if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize())
62                  return _L<cse::String>();
63  
64          _S<ios::String> statement_;
65          By by(bys.Last());
66 <        
66 >
67          statement_ << _B("SELECT DISTINCT ") << by << _B(" FROM files WHERE live = TRUE ");
68  
69          bys.RemoveLast();
# Line 70 | Line 71 | _L<cse::String> Library::GetItems(_L<By>
71          _foreach (const _L<By>, by_, bys)
72                  statement_ << _B("AND ") << *by_ << _B(" = ? ");
73  
74 <        statement_ << _B("ORDER BY ") << by;
74 <
75 <        _rforeach (const _L<By>, by_, bys)
76 <                statement_ << _B(", ") << *by_;
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(by));
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