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

Add AlbumTrack

parent 6a448852
......@@ -10,11 +10,9 @@ class IAlbumTrack
public:
virtual ~IAlbumTrack() {}
virtual const std::string& artist() = 0;
virtual const std::string& genre() = 0;
virtual const std::string& title() = 0;
virtual unsigned int trackNumber() = 0;
virtual IAlbum* album() = 0;
};
......
#include "AlbumTrack.h"
#include "Album.h"
#include "SqliteTools.h"
AlbumTrack::AlbumTrak( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
, m_album( NULL )
{
m_id = sqlite3_column_int( stmt, 1 );
m_title = (const char*)sqlite3_column_text( stmt, 2 );
m_genre = (const char*)sqlite3_column_text( stmt, 3 );
m_trackNumber = sqlite3_column_int( stmt, 4 );
m_albumId = sqlite3_column_int( stmt, 5 );
}
bool AlbumTrack::createTable(sqlite3* dbConnection)
{
const char* req = "CREATE TABLE IF NOT EXISTS AlbumTrack ("
"id_track INTEGER PRIMARY KEY AUTO INCREMENT,"
"title TEXT,"
"genre TEXT,"
"track_number UNSIGNED INTEGER,"
"album_id UNSIGNED INTEGER NOT NULL,"
"FOREIGN KEY (album_id) REFERENCES Album(id_album) ON DELETE CASCADE
")";
return SqliteTools::CreateTable( dbConnection, req );
}
const std::string& AlbumTrack::genre()
{
return m_genre;
}
const std::string& AlbumTrack::title()
{
return m_title;
}
unsigned int AlbumTrack::trackNumber()
{
return m_trackNumber;
}
IAlbum* AlbumTrack::album()
{
if ( m_album == NULL && m_albumId != 0 )
{
const char* req = "SELECT * FROM Album WHERE id_album = ?";
sqlite3_stmt *stmt;
int res = sqlite3_prepare_v2( m_dbConnection, req, -1, &stmt, NULL );
if ( res != SQLITE_OK )
return NULL;
sqlite3_bind_int( stmt, 1, m_albumId );
res = sqlite3_step( stmt );
m_album = new Album( m_dbConnection, stmt );
sqlite3_finalize( stmt );
}
return m_album;
}
#ifndef ALBUMTRACK_H
#define ALBUMTRACK_H
#include <sqlite3.h>
#include <string>
#include "IAlbumTrack.h"
class Album;
class AlbumTrack : public IAlbumTrack
{
public:
AlbumTrack();
static bool createTable( sqlite3* dbConnection );
virtual const std::string&genre();
virtual const std::string&title();
virtual unsigned int trackNumber();
virtual IAlbum*album();
private:
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_title;
std::string m_genre;
unsigned int m_trackNumber;
unsigned int m_albumId;
Album* m_album;
};
#endif // ALBUMTRACK_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