ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/Library.cpp
Revision: 554
Committed: 2005-07-10T04:22:54-07:00 (19 years, 11 months ago) by douglas
File size: 2354 byte(s)
Log Message:
Did a bunch of stuff, added a make.sh, it doesn't seem to be ready for working yet.

File Contents

# Content
1 // Library
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include <menes/c++/standard.hh>
8
9 #include <menes/dbi/resultset.hpp>
10
11 #include "Library.hpp"
12
13 Library::Library(const _R<dbi::Connection>& connection) : connection(connection)
14 {
15 connection->Execute(_B("UPDATE files SET live = FALSE"));
16 }
17
18 _L<MediaFolder> Library::GetFolders(unsigned page) const
19 {
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())
24 folders.InsertLast(GetFolder(roots->GetString(_B("root"))));
25
26 return folders;
27 }
28
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>();
33
34 _S<ios::String> statement_;
35
36 statement_ << _B("SELECT path FROM files WHERE live = TRUE ");
37
38 _foreach (const _L<By>, by, bys)
39 statement_ << _B("AND ") << *by << _B(" = ? ");
40
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
53 while (paths->MoveNext())
54 files.InsertLast(GetFile(paths->GetString(_B("path"))));
55
56 return files;
57 }
58
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
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 }

Properties

Name Value
svn:eol-style native
svn:keywords Id