ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/MediaFolder.cpp
(Generate patch)

Comparing DecentralizedMedia/MediaFolder.cpp (file contents):
Revision 499 by douglas, 2005-06-17T14:11:19-07:00 vs.
Revision 546 by douglas, 2005-07-03T22:13:07-07:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 < #include "MediaFolder.hpp"
7 > #include <menes/standard.hh>
8  
9   #include <menes-dbi/resultset.hpp>
10  
11 < MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path)
11 > #include "MediaFolder.hpp"
12 >
13 > MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path)
14   {
15 <        // XXX: implement
15 >        _R<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath()));
16 >
17 >        if (root_->MoveNext())
18 >                root = root_->GetString(_B("root"));
19   }
20  
21 < MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root)
21 > MediaFolder::MediaFolder(const _R<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root)
22   {
23 <        _H<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ? AND root = ?"))->Execute(path.GetPath(), root.GetPath()));
19 <
20 <        if (!path_->MoveNext())
21 <        {
22 <                connection->Parse(_B("DELETE FROM folders WHERE path = ?"))->Execute(path.GetPath());
23 >        _R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath()));
24  
25 +        if (path_->MoveNext())
26 +                if (path.GetPath() != root.GetPath())
27 +                        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                          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());
28        }
35   }
36  
37   _L<MediaFile> MediaFolder::GetFiles() const
38   {
39 <        _H<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
39 >        _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
40          _L<MediaFile> files;
41  
42          while (paths->MoveNext())
# Line 41 | Line 47 | _L<MediaFile> MediaFolder::GetFiles() co
47  
48   _L<MediaFolder> MediaFolder::GetFolders() const
49   {
50 <        _H<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
50 >        _R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath()));
51          _L<MediaFolder> folders;
52  
53          while (paths->MoveNext())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines