ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/MediaFolder.cpp
Revision: 549
Committed: 2005-07-04T21:28:02-07:00 (19 years, 11 months ago) by douglas
File size: 2089 byte(s)
Log Message:
WTF!

File Contents

# User Rev Content
1 douglas 476 // Media Folder
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 516 #include <menes/standard.hh>
8 douglas 478
9 douglas 549 #include <menes/dbi/resultset.hpp>
10 douglas 489
11 douglas 516 #include "MediaFolder.hpp"
12    
13 douglas 542 MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path)
14 douglas 478 {
15 douglas 541 _R<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath()));
16 douglas 500
17     if (root_->MoveNext())
18     root = root_->GetString(_B("root"));
19 douglas 478 }
20    
21 douglas 542 MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root)
22 douglas 496 {
23 douglas 541 _R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath()));
24 douglas 496
25 douglas 500 if (path_->MoveNext())
26 douglas 498 if (path.GetPath() != root.GetPath())
27 douglas 500 connection->Parse(_B("UPDATE folders SET folder = ?, root = ? WHERE path = ?"))->Execute(path.GetParent().GetPath(), root.GetPath(), path.GetPath());
28     else
29     connection->Parse(_B("UPDATE folders SET folder = NULL, root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath());
30     else
31     if (path.GetPath() != root.GetPath())
32 douglas 498 connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, ?, ?)"))->Execute(path.GetPath(), path.GetParent().GetPath(), root.GetPath());
33     else
34     connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, NULL, ?)"))->Execute(path.GetPath(), root.GetPath());
35 douglas 496 }
36    
37 douglas 478 _L<MediaFile> MediaFolder::GetFiles() const
38     {
39 douglas 541 _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
40 douglas 478 _L<MediaFile> files;
41    
42 douglas 488 while (paths->MoveNext())
43     files.InsertLast(MediaFile(connection, paths->GetString(_B("path"))));
44 douglas 478
45     return files;
46     }
47    
48     _L<MediaFolder> MediaFolder::GetFolders() const
49     {
50 douglas 541 _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
51 douglas 478 _L<MediaFolder> folders;
52    
53 douglas 488 while (paths->MoveNext())
54     folders.InsertLast(MediaFolder(connection, paths->GetString(_B("path"))));
55 douglas 478
56     return folders;
57     }

Properties

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