ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/Library.cpp
Revision: 553
Committed: 2005-07-07T04:24:27-07:00 (19 years, 11 months ago) by douglas
File size: 2250 byte(s)
Log Message:
Insanity!

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() const
19 {
20 _R<dbi::ResultSet> roots(connection->Execute(_B("SELECT DISTINCT root FROM files WHERE live = TRUE ORDER By root")));
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) 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 _rforeach (const _L<By>, by, bys)
42 statement_ << _B(by + 1 == _set.End() ? "ORDER BY " : ", ") << *by;
43
44 _R<dbi::Statement> statement(connection->Parse(statement_));
45
46 _foreach (const _L<cse::String>, item, items)
47 statement->Set(_index, *item);
48
49 _R<dbi::ResultSet> paths(statement->Execute());
50 _L<MediaFile> files;
51
52 while (paths->MoveNext())
53 files.InsertLast(GetFile(paths->GetString(_B("path"))));
54
55 return files;
56 }
57
58 _L<cse::String> Library::GetItems(_L<By> bys, _L<cse::String> items) const
59 {
60 if (bys.IsEmpty() || ext::Contains(bys, By::LAST) || bys.GetSize() - 1 != items.GetSize())
61 return _L<cse::String>();
62
63 _S<ios::String> statement_;
64 By by(bys.Last());
65
66 statement_ << _B("SELECT DISTINCT ") << by << _B(" FROM files WHERE live = TRUE ");
67
68 bys.RemoveLast();
69
70 _foreach (const _L<By>, by_, bys)
71 statement_ << _B("AND ") << *by_ << _B(" = ? ");
72
73 statement_ << _B("ORDER BY ") << by;
74
75 _rforeach (const _L<By>, by_, bys)
76 statement_ << _B(", ") << *by_;
77
78 _R<dbi::Statement> statement(connection->Parse(statement_));
79
80 _foreach (const _L<cse::String>, item, items)
81 statement->Set(_index, *item);
82
83 _R<dbi::ResultSet> items_(statement->Execute());
84
85 items.Clear();
86
87 while (items_->MoveNext())
88 items.InsertLast(items_->GetString(by));
89
90 return items;
91 }

Properties

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