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(_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 |
> |
else |
20 |
> |
throw; |
21 |
|
} |
22 |
|
|
23 |
< |
MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path) |
23 |
> |
MediaFolder::MediaFolder(_R<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path), root(root) |
24 |
|
{ |
25 |
< |
_H<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath())); |
25 |
> |
_R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM folders WHERE path = ?"))->Execute(path.GetPath())); |
26 |
|
|
27 |
< |
if (!path_->MoveNext()) |
28 |
< |
connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, ?, ?)"))->Execute(path.GetPath(), path.GetParent().GetPath(), root.GetPath()); |
27 |
> |
if (path_->MoveNext()) |
28 |
> |
if (path.GetPath() != root.GetPath()) |
29 |
> |
connection->Parse(_B("UPDATE folders SET folder = ?, root = ? WHERE path = ?"))->Execute(path.GetParent().GetPath(), root.GetPath(), path.GetPath()); |
30 |
> |
else |
31 |
> |
connection->Parse(_B("UPDATE folders SET folder = NULL, root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath()); |
32 |
> |
else |
33 |
> |
if (path.GetPath() != root.GetPath()) |
34 |
> |
connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, ?, ?)"))->Execute(path.GetPath(), path.GetParent().GetPath(), root.GetPath()); |
35 |
> |
else |
36 |
> |
connection->Parse(_B("INSERT INTO folders (path, folder, root) VALUES (?, NULL, ?)"))->Execute(path.GetPath(), root.GetPath()); |
37 |
|
} |
38 |
|
|
39 |
|
_L<MediaFile> MediaFolder::GetFiles() const |
40 |
|
{ |
41 |
< |
_H<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath())); |
41 |
> |
_R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM files WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath())); |
42 |
|
_L<MediaFile> files; |
43 |
|
|
44 |
|
while (paths->MoveNext()) |
49 |
|
|
50 |
|
_L<MediaFolder> MediaFolder::GetFolders() const |
51 |
|
{ |
52 |
< |
_H<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath())); |
52 |
> |
_R<dbi::ResultSet> paths(connection->Parse(_B("SELECT path FROM folders WHERE live = TRUE AND folder = ?"))->Execute(path.GetPath())); |
53 |
|
_L<MediaFolder> folders; |
54 |
|
|
55 |
|
while (paths->MoveNext()) |