10 |
|
|
11 |
|
MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path) : connection(connection), path(path) |
12 |
|
{ |
13 |
< |
// XXX: implement |
13 |
> |
_H<dbi::ResultSet> root_(connection->Parse(_B("SELECT root FROM folders WHERE path = ?"))->Execute(path.GetPath())); |
14 |
> |
|
15 |
> |
if (root_->MoveNext()) |
16 |
> |
root = root_->GetString(_B("root")); |
17 |
> |
else |
18 |
> |
throw; |
19 |
|
} |
20 |
|
|
21 |
< |
MediaFolder::MediaFolder(_H<dbi::Connection>& connection, const api::Path& path, const api::Path& root) : connection(connection), path(path) |
21 |
> |
MediaFolder::MediaFolder(_H<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 = ?"))->Execute(path.GetPath())); |
24 |
|
|
25 |
< |
if (!path_->MoveNext()) |
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 |