--- DecentralizedMedia/MediaFile.cpp 2005/06/09 00:16:59 478 +++ DecentralizedMedia/MediaFile.cpp 2005/07/11 04:18:35 555 @@ -4,14 +4,53 @@ // // $Id$ +#include + +#include + #include "MediaFile.hpp" -MediaFile::MediaFile(const ext::String& name) : name(name) +MediaFile::MediaFile(const _R& connector, const api::Path& path) : connector(connector), path(path) { - // XXX: implement + _R connection(connector->Connect()); + _R info(connection->Parse(_B("SELECT artist, title, album, genre FROM files WHERE path = ?"))->Execute(path.GetPath())); + + if (info->MoveNext()) + { + artist = info->GetString(_B("artist")); + title = info->GetString(_B("title")); + album = info->GetString(_B("album")); + genre = info->GetString(_B("genre")); + } + + connector->Release(connection); } -MediaFile::MediaFile(const ext::String& name, const ext::String& artist, const ext::String& title, const ext::String& album, const ext::String& genre) : name(name), artist(artist), title(title), album(album), genre(genre) +MediaFile::MediaFile(const _R& connector, const api::Path& path, const cse::String& artist, const cse::String& title, const cse::String& album, const cse::String& genre, const api::Path& root) : connector(connector), path(path), artist(artist), title(title), album(album), genre(genre) { - // XXX: implement + _R connection(connector->Connect()); + _R path_(connection->Parse(_B("SELECT path FROM files WHERE path = ?"))->Execute(path.GetPath())); + + if (path_->MoveNext()) + { + connection->Parse(_B("UPDATE files SET live = TRUE WHERE path = ?"))->Execute(path.GetPath()); + + if (!artist.IsEmpty()) + connection->Parse(_B("UPDATE files SET artist = ? WHERE path = ?"))->Execute(artist, path.GetPath()); + + if (!title.IsEmpty()) + connection->Parse(_B("UPDATE files SET title = ? WHERE path = ?"))->Execute(title, path.GetPath()); + + if (!album.IsEmpty()) + connection->Parse(_B("UPDATE files SET album = ? WHERE path = ?"))->Execute(album, path.GetPath()); + + if (!genre.IsEmpty()) + connection->Parse(_B("UPDATE files SET genre = ? WHERE path = ?"))->Execute(genre, path.GetPath()); + + connection->Parse(_B("UPDATE files SET root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath()); + } + else + connection->Parse(_B("INSERT INTO files (path, artist, title, album, genre, folder, root) VALUES (?, ?, ?, ?, ?, ?, ?)"))->Execute(path.GetPath(), artist, title, album, genre, path.GetParent().GetPath(), root.GetPath()); + + connector->Release(connection); }