ShowEpisode.cpp 2.01 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1 2 3 4 5 6 7
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "Show.h"

ShowEpisode::ShowEpisode( sqlite3* dbConnection, sqlite3_stmt* stmt )
    : m_dbConnection( dbConnection )
{
8 9 10 11 12 13 14 15 16
    m_id = sqlite3_column_int( stmt, 0 );
    m_artworkUrl = (const char*)sqlite3_column_text( stmt, 1 );
    m_episodeNumber = sqlite3_column_int( stmt, 2 );
    m_lastSyncDate = sqlite3_column_int( stmt, 3 );
    m_name = (const char*)sqlite3_column_text( stmt, 4 );
    m_seasonNumber = sqlite3_column_int( stmt, 5 );
    m_shortSummary = (const char*)sqlite3_column_text( stmt, 6 );
    m_tvdbId = (const char*)sqlite3_column_text( stmt, 7 );
    m_showId = sqlite3_column_int( stmt, 8 );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
17 18 19
}


Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
20
const std::string& ShowEpisode::artworkUrl()
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
{
    return m_artworkUrl;
}

unsigned int ShowEpisode::episodeNumber()
{
    return m_episodeNumber;
}

time_t ShowEpisode::lastSyncDate()
{
    return m_lastSyncDate;
}

const std::string&ShowEpisode::name()
{
    return m_name;
}

unsigned int ShowEpisode::seasonNuber()
{
    return m_seasonNumber;
}

const std::string&ShowEpisode::shortSummary()
{
    return m_shortSummary;
}

const std::string&ShowEpisode::tvdbId()
{
    return m_tvdbId;
}

IShow* ShowEpisode::show()
{
    if ( m_show == NULL && m_showId != 0 )
    {
        const char* req = "SELECT * FROM Show WHERE id_show = ?";
        m_show = SqliteTools::fetchOne<Show>( m_dbConnection, req, m_showId );
    }
    return m_show;
}

bool ShowEpisode::createTable(sqlite3* dbConnection)
{
67 68
    const char* req = "CREATE TABLE IF NOT EXISTS ShowEpisode("
                "id_episode INTEGER PRIMARY KEY AUTOINCREMENT,"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
69 70 71 72 73 74 75 76 77 78
                "artwork_url TEXT,"
                "episode_number UNSIGNED INT,"
                "last_sync_date UNSIGNED INT,"
                "name TEXT,"
                "season_number UNSIGNED INT,"
                "episode_summary TEXT,"
                "tvdb_id TEXT,"
                "show_id UNSIGNED INT,"
                "FOREIGN KEY(show_id) REFERENCES Show(id_show)"
            ")";
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
79
    return SqliteTools::createTable( dbConnection, req );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
80
}