1 |
// Media File |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include <cxx/standard.hh> |
8 |
|
9 |
#include <dbi/resultset.hpp> |
10 |
|
11 |
#include "MediaFile.hpp" |
12 |
|
13 |
MediaFile::MediaFile(const _R<Connector>& connector, const api::Path& path) : connector(connector), path(path) |
14 |
{ |
15 |
_R<dbi::Connection> connection(connector->Connect()); |
16 |
_R<dbi::ResultSet> info(connection->Parse(_B("SELECT artist, title, album, genre FROM files WHERE path = ?"))->Execute(path.GetPath())); |
17 |
|
18 |
if (info->MoveNext()) |
19 |
{ |
20 |
artist = info->GetString(_B("artist")); |
21 |
title = info->GetString(_B("title")); |
22 |
album = info->GetString(_B("album")); |
23 |
genre = info->GetString(_B("genre")); |
24 |
} |
25 |
|
26 |
connector->Release(connection); |
27 |
} |
28 |
|
29 |
MediaFile::MediaFile(const _R<Connector>& 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) |
30 |
{ |
31 |
_R<dbi::Connection> connection(connector->Connect()); |
32 |
_R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM files WHERE path = ?"))->Execute(path.GetPath())); |
33 |
|
34 |
if (path_->MoveNext()) |
35 |
{ |
36 |
connection->Parse(_B("UPDATE files SET live = TRUE WHERE path = ?"))->Execute(path.GetPath()); |
37 |
|
38 |
if (!artist.IsEmpty()) |
39 |
connection->Parse(_B("UPDATE files SET artist = ? WHERE path = ?"))->Execute(artist, path.GetPath()); |
40 |
|
41 |
if (!title.IsEmpty()) |
42 |
connection->Parse(_B("UPDATE files SET title = ? WHERE path = ?"))->Execute(title, path.GetPath()); |
43 |
|
44 |
if (!album.IsEmpty()) |
45 |
connection->Parse(_B("UPDATE files SET album = ? WHERE path = ?"))->Execute(album, path.GetPath()); |
46 |
|
47 |
if (!genre.IsEmpty()) |
48 |
connection->Parse(_B("UPDATE files SET genre = ? WHERE path = ?"))->Execute(genre, path.GetPath()); |
49 |
|
50 |
connection->Parse(_B("UPDATE files SET root = ? WHERE path = ?"))->Execute(root.GetPath(), path.GetPath()); |
51 |
} |
52 |
else |
53 |
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()); |
54 |
|
55 |
connector->Release(connection); |
56 |
} |