Commit d5d2d7a5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add album fetching from a file

parent fe1de73f
......@@ -51,3 +51,18 @@ bool Album::CreateTable(sqlite3* dbConnection)
"TEXT artwork_url, UNSIGNED INTEGER last_sync_date)";
return SqliteTools::CreateTable( dbConnection, req );
}
Album* Album::Fetch(sqlite3* dbConnection, unsigned int albumTrackId)
{
const char* req = "SELECT * FROM Album WHERE id_album = ?";
sqlite3_stmt *stmt;
int res = sqlite3_prepare_v2( dbConnection, req, -1, &stmt, NULL );
if ( res != SQLITE_OK )
return NULL;
sqlite3_bind_int( stmt, 1, albumTrackId );
if ( sqlite3_step( stmt ) != SQLITE_ROW )
return NULL;
Album* album = new Album( dbConnection, stmt );
sqlite3_finalize( stmt );
return album;
}
......@@ -18,6 +18,7 @@ class Album : public IAlbum
virtual time_t lastSyncDate();
static bool CreateTable( sqlite3* dbConnection );
static Album* Fetch( sqlite3* dbConnection, unsigned int albumTrackId)
protected:
sqlite3* m_dbConnection;
......
#include <cassert>
#include "File.h"
#include "SqliteTools.h"
File::File( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
, m_albumTrack( NULL )
, m_showEpisode( NULL )
, m_labels( NULL )
{
m_id = sqlite3_column_int( stmt, 0 );
m_type = (Type)sqlite3_column_int( stmt, 1 );
m_duration = sqlite3_column_int( stmt, 2 );
m_albumTrackId = sqlite3_column_int( stmt, 3 );
}
File::File(sqlite3* dbConnection)
: m_dbConnection( dbConnection )
File::File()
: m_dbConnection( NULL )
, m_id( 0 )
{
}
bool File::insert()
bool File::insert( sqlite3* dbConnection )
{
assert( m_dbConnection == NULL );
m_dbConnection = dbConnection;
sqlite3_stmt* stmt;
std::string req = "INSERT INTO File VALUES(NULL, ?, ?)";
std::string req = "INSERT INTO File VALUES(NULL, ?, ?, ?)";
if ( sqlite3_prepare_v2( m_dbConnection, req.c_str(), -1, &stmt, NULL ) != SQLITE_OK )
return false;
sqlite3_bind_int( stmt, 1, m_type );
sqlite3_bind_int( stmt, 2, m_duration );
sqlite3_bind_int( stmt, 3, m_albumTrackId );
if ( sqlite3_step( stmt ) != SQLITE_DONE )
return false;
m_id = sqlite3_last_insert_rowid( m_dbConnection );
......@@ -31,6 +40,11 @@ bool File::insert()
IAlbumTrack*File::albumTrack()
{
if ( m_albumTrack == NULL && m_albumTrackId != 0 )
{
m_albumTrack = AlbumTrack::fetch( m_albumTrackId );
}
return m_albumTrack;
}
const std::string&File::artworkUrl()
......@@ -54,6 +68,7 @@ bool File::CreateTable(sqlite3* connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS File("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER, duration UNSIGNED INTEGER)";
"type INTEGER, duration UNSIGNED INTEGER,"
"album_track_id UNSIGNED INTEGER)";
return SqliteTools::CreateTable( connection, req );
}
......@@ -5,21 +5,25 @@
#include "IFile.h"
class Album;
class ShowEpisode;
class AlbumTrack;
class File : public IFile
{
public:
enum Type
{
Video, // Any video file, not being a tv show episode
Audio, // Any kind of audio file, not being an album track
ShowEpisode,
AlbumTrack,
VideoType, // Any video file, not being a tv show episode
AudioType, // Any kind of audio file, not being an album track
ShowEpisodeType,
AlbumTrackType,
};
File(sqlite3* dbConnection , sqlite3_stmt* stmt);
File( sqlite3* dbConnection );
File();
bool insert();
bool insert(sqlite3* dbConnection);
virtual IAlbumTrack* albumTrack();
virtual const std::string& artworkUrl();
......@@ -36,8 +40,13 @@ class File : public IFile
unsigned int m_id;
Type m_type;
unsigned int m_duration;
unsigned int m_albumTrackId;
// Auto fetched related properties
Album* m_album;
AlbumTrack* m_albumTrack;
ShowEpisode* m_showEpisode;
std::vector<ILabel*>* m_labels;
};
#endif // FILE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment