ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/MediaFile.cpp
Revision: 555
Committed: 2005-07-10T21:18:35-07:00 (19 years, 11 months ago) by douglas
File size: 2167 byte(s)
Log Message:
Connector!

File Contents

# User Rev Content
1 douglas 475 // Media File
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 553 #include <menes/c++/standard.hh>
8 douglas 476
9 douglas 549 #include <menes/dbi/resultset.hpp>
10 douglas 489
11 douglas 516 #include "MediaFile.hpp"
12    
13 douglas 555 MediaFile::MediaFile(const _R<Connector>& connector, const api::Path& path) : connector(connector), path(path)
14 douglas 476 {
15 douglas 555 _R<dbi::Connection> connection(connector->Connect());
16 douglas 541 _R<dbi::ResultSet> info(connection->Parse(_B("SELECT artist, title, album, genre FROM files WHERE path = ?"))->Execute(path.GetPath()));
17 douglas 488
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 douglas 555
26     connector->Release(connection);
27 douglas 476 }
28 douglas 478
29 douglas 555 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 douglas 478 {
31 douglas 555 _R<dbi::Connection> connection(connector->Connect());
32 douglas 541 _R<dbi::ResultSet> path_(connection->Parse(_B("SELECT path FROM files WHERE path = ?"))->Execute(path.GetPath()));
33 douglas 500
34     if (path_->MoveNext())
35     {
36 douglas 514 connection->Parse(_B("UPDATE files SET live = TRUE WHERE path = ?"))->Execute(path.GetPath());
37    
38 douglas 500 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 douglas 555
55     connector->Release(connection);
56 douglas 478 }

Properties

Name Value
svn:eol-style native
svn:keywords Id