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

Move Sqlite & Cache headers in their own directories & namespace

parent 778876ee
#include "Album.h"
#include "AlbumTrack.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
const std::string policy::AlbumTable::Name = "Album";
const std::string policy::AlbumTable::CacheColumn = "id_album";
......@@ -11,10 +11,10 @@ Album::Album(DBConnection dbConnection, sqlite3_stmt* stmt)
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 0 );
m_title = Traits<std::string>::Load( stmt, 1 );
m_title = sqlite::Traits<std::string>::Load( stmt, 1 );
m_releaseDate = sqlite3_column_int( stmt, 2 );
m_shortSummary = Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = Traits<std::string>::Load( stmt, 4 );
m_shortSummary = sqlite::Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = sqlite::Traits<std::string>::Load( stmt, 4 );
m_lastSyncDate = sqlite3_column_int( stmt, 5 );
}
......@@ -45,7 +45,7 @@ bool Album::setReleaseDate( time_t date )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET release_date = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
return false;
m_releaseDate = date;
return true;
......@@ -60,7 +60,7 @@ bool Album::setShortSummary( const std::string& summary )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET short_summary = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
return false;
m_shortSummary = summary;
return true;
......@@ -75,7 +75,7 @@ bool Album::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET artwork_url = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
......@@ -90,7 +90,7 @@ std::vector<std::shared_ptr<IAlbumTrack>> Album::tracks() const
{
static const std::string req = "SELECT * FROM " + policy::AlbumTrackTable::Name
+ " WHERE album_id = ?";
return SqliteTools::fetchAll<AlbumTrack, IAlbumTrack>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<AlbumTrack, IAlbumTrack>( m_dbConnection, req, m_id );
}
AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
......@@ -121,7 +121,7 @@ bool Album::createTable(DBConnection dbConnection )
"artwork_url TEXT,"
"UNSIGNED INTEGER last_sync_date"
")";
return SqliteTools::executeRequest( dbConnection, req );
return sqlite::Tools::executeRequest( dbConnection, req );
}
AlbumPtr Album::create(DBConnection dbConnection, const std::string& title )
......
......@@ -6,7 +6,7 @@
#include "IMediaLibrary.h"
#include "Cache.h"
#include "database/Cache.h"
#include "IAlbum.h"
class Album;
......
#include "AlbumTrack.h"
#include "Album.h"
#include "File.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
const std::string policy::AlbumTrackTable::Name = "AlbumTrack";
const std::string policy::AlbumTrackTable::CacheColumn = "id_track";
......@@ -11,12 +11,12 @@ AlbumTrack::AlbumTrack( DBConnection dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
, m_album( nullptr )
{
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_title = Traits<std::string>::Load( stmt, 1 );
m_genre = Traits<std::string>::Load( stmt, 2 );
m_trackNumber = Traits<unsigned int>::Load( stmt, 3 );
m_artist = Traits<std::string>::Load( stmt, 4 );
m_albumId = Traits<unsigned int>::Load( stmt, 5 );
m_id = sqlite::Traits<unsigned int>::Load( stmt, 0 );
m_title = sqlite::Traits<std::string>::Load( stmt, 1 );
m_genre = sqlite::Traits<std::string>::Load( stmt, 2 );
m_trackNumber = sqlite::Traits<unsigned int>::Load( stmt, 3 );
m_artist = sqlite::Traits<std::string>::Load( stmt, 4 );
m_albumId = sqlite::Traits<unsigned int>::Load( stmt, 5 );
}
AlbumTrack::AlbumTrack( const std::string& title, unsigned int trackNumber, unsigned int albumId )
......@@ -44,7 +44,7 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
"album_id UNSIGNED INTEGER NOT NULL,"
"FOREIGN KEY (album_id) REFERENCES Album(id_album) ON DELETE CASCADE"
")";
return SqliteTools::executeRequest( dbConnection, req );
return sqlite::Tools::executeRequest( dbConnection, req );
}
AlbumTrackPtr AlbumTrack::create(DBConnection dbConnection, unsigned int albumId, const std::string& name, unsigned int trackNb)
......@@ -67,7 +67,7 @@ bool AlbumTrack::setGenre(const std::string& genre)
{
static const std::string req = "UPDATE " + policy::AlbumTrackTable::Name
+ " SET genre = ? WHERE id_track = ? ";
if ( SqliteTools::executeUpdate( m_dbConnection, req, genre, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, genre, m_id ) == false )
return false;
m_genre = genre;
return true;
......@@ -116,7 +116,7 @@ bool AlbumTrack::setArtist(const std::string& artist)
{
static const std::string req = "UPDATE " + policy::AlbumTrackTable::Name +
" SET artist = ? WHERE id_track = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artist, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artist, m_id ) == false )
return false;
m_artist = artist;
return true;
......@@ -126,5 +126,5 @@ std::vector<FilePtr> AlbumTrack::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE album_track_id = ? ";
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
......@@ -6,7 +6,7 @@
#include "IAlbumTrack.h"
#include "IMediaLibrary.h"
#include "Cache.h"
#include "database/Cache.h"
class Album;
class AlbumTrack;
......
......@@ -6,11 +6,11 @@ unsigned int AudioTrack::* const policy::AudioTrackTable::PrimaryKey = &AudioTra
AudioTrack::AudioTrack( DBConnection dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
, m_id( Traits<unsigned int>::Load( stmt, 0 ) )
, m_codec( Traits<std::string>::Load( stmt, 1 ) )
, m_bitrate( Traits<unsigned int>::Load( stmt, 2 ) )
, m_sampleRate( Traits<unsigned int>::Load( stmt, 3 ) )
, m_nbChannels( Traits<unsigned int>::Load( stmt, 4 ) )
, m_id( sqlite::Traits<unsigned int>::Load( stmt, 0 ) )
, m_codec( sqlite::Traits<std::string>::Load( stmt, 1 ) )
, m_bitrate( sqlite::Traits<unsigned int>::Load( stmt, 2 ) )
, m_sampleRate( sqlite::Traits<unsigned int>::Load( stmt, 3 ) )
, m_nbChannels( sqlite::Traits<unsigned int>::Load( stmt, 4 ) )
{
}
......@@ -59,7 +59,7 @@ bool AudioTrack::createTable( DBConnection dbConnection )
"nb_channels UNSIGNED INTEGER,"
"UNIQUE ( codec, bitrate ) ON CONFLICT FAIL"
")";
return SqliteTools::executeRequest( dbConnection, req );
return sqlite::Tools::executeRequest( dbConnection, req );
}
AudioTrackPtr AudioTrack::fetch(DBConnection dbConnection, const std::string& codec,
......@@ -67,7 +67,7 @@ AudioTrackPtr AudioTrack::fetch(DBConnection dbConnection, const std::string& co
{
static const std::string req = "SELECT * FROM " + policy::AudioTrackTable::Name
+ " WHERE codec = ? AND bitrate = ? AND samplerate = ? AND nb_channels = ?";
return SqliteTools::fetchOne<AudioTrack>( dbConnection, req, codec, bitrate, sampleRate, nbChannels );
return sqlite::Tools::fetchOne<AudioTrack>( dbConnection, req, codec, bitrate, sampleRate, nbChannels );
}
AudioTrackPtr AudioTrack::create( DBConnection dbConnection, const std::string& codec,
......
......@@ -3,7 +3,7 @@
#include "IAudioTrack.h"
#include "IMediaLibrary.h"
#include "Cache.h"
#include "database/Cache.h"
class AudioTrack;
......
......@@ -25,8 +25,8 @@ list(APPEND HEADERS_LIST
${CMAKE_SOURCE_DIR}/include/factory/IFileSystem.h
Cache.h
SqliteTools.h
database/Cache.h
database/SqliteTools.h
filesystem/IDirectory.h
filesystem/IFile.h
......
......@@ -10,7 +10,7 @@
#include "Label.h"
#include "Movie.h"
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
#include "VideoTrack.h"
const std::string policy::FileTable::Name = "File";
......@@ -27,8 +27,8 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_playCount = sqlite3_column_int( stmt, 4 );
m_showEpisodeId = sqlite3_column_int( stmt, 5 );
m_mrl = (const char*)sqlite3_column_text( stmt, 6 );
m_movieId = Traits<unsigned int>::Load( stmt, 7 );
m_folderId = Traits<unsigned int>::Load( stmt, 8 );
m_movieId = sqlite::Traits<unsigned int>::Load( stmt, 7 );
m_folderId = sqlite::Traits<unsigned int>::Load( stmt, 8 );
m_isReady = m_type != UnknownType;
}
......@@ -81,7 +81,7 @@ bool File::setAlbumTrack( AlbumTrackPtr albumTrack )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET album_track_id = ? "
"WHERE id_file = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, albumTrack->id(), m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, albumTrack->id(), m_id ) == false )
return false;
m_albumTrackId = albumTrack->id();
m_albumTrack = albumTrack;
......@@ -106,7 +106,7 @@ bool File::setShowEpisode(ShowEpisodePtr showEpisode)
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET show_episode_id = ? WHERE id_file = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, showEpisode->id(), m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, showEpisode->id(), m_id ) == false )
return false;
m_showEpisodeId = showEpisode->id();
m_showEpisode = showEpisode;
......@@ -118,7 +118,7 @@ std::vector<std::shared_ptr<ILabel> > File::labels()
static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label "
"WHERE lfr.id_file = ?";
return SqliteTools::fetchAll<Label, ILabel>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<Label, ILabel>( m_dbConnection, req, m_id );
}
int File::playCount() const
......@@ -144,7 +144,7 @@ bool File::setMovie( MoviePtr movie )
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET movie_id = ? WHERE id_file = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, movie->id(), m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, movie->id(), m_id ) == false )
return false;
m_movie = movie;
m_movieId = movie->id();
......@@ -162,7 +162,7 @@ bool File::addVideoTrack(const std::string& codec, unsigned int width, unsigned
if ( track == nullptr )
return false;
}
return SqliteTools::executeRequest( m_dbConnection, req, track->id(), m_id );
return sqlite::Tools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
std::vector<VideoTrackPtr> File::videoTracks()
......@@ -170,7 +170,7 @@ std::vector<VideoTrackPtr> File::videoTracks()
static const std::string req = "SELECT t.* FROM " + policy::VideoTrackTable::Name +
" t LEFT JOIN VideoTrackFileRelation vtfr ON vtfr.id_track = t.id_track"
" WHERE vtfr.id_file = ?";
return SqliteTools::fetchAll<VideoTrack, IVideoTrack>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<VideoTrack, IVideoTrack>( m_dbConnection, req, m_id );
}
bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
......@@ -185,7 +185,7 @@ bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
if ( track == nullptr )
return false;
}
return SqliteTools::executeRequest( m_dbConnection, req, track->id(), m_id );
return sqlite::Tools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
std::vector<AudioTrackPtr> File::audioTracks()
......@@ -193,7 +193,7 @@ std::vector<AudioTrackPtr> File::audioTracks()
static const std::string req = "SELECT t.* FROM " + policy::AudioTrackTable::Name +
" t LEFT JOIN AudioTrackFileRelation atfr ON atfr.id_track = t.id_track"
" WHERE atfr.id_file = ?";
return SqliteTools::fetchAll<AudioTrack, IAudioTrack>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<AudioTrack, IAudioTrack>( m_dbConnection, req, m_id );
}
bool File::isStandAlone()
......@@ -238,7 +238,7 @@ bool File::createTable( DBConnection connection )
"FOREIGN KEY (folder_id) REFERENCES " + policy::FolderTable::Name
+ "(id_folder) ON DELETE CASCADE"
")";
if ( SqliteTools::executeRequest( connection, req ) == false )
if ( sqlite::Tools::executeRequest( connection, req ) == false )
return false;
req = "CREATE TABLE IF NOT EXISTS VideoTrackFileRelation("
"id_track INTEGER,"
......@@ -249,7 +249,7 @@ bool File::createTable( DBConnection connection )
"FOREIGN KEY ( id_file ) REFERENCES " + policy::FileTable::Name
+ "(id_file) ON DELETE CASCADE"
")";
if ( SqliteTools::executeRequest( connection, req ) == false )
if ( sqlite::Tools::executeRequest( connection, req ) == false )
return false;
req = "CREATE TABLE IF NOT EXISTS AudioTrackFileRelation("
"id_track INTEGER,"
......@@ -260,7 +260,7 @@ bool File::createTable( DBConnection connection )
"FOREIGN KEY ( id_file ) REFERENCES " + policy::FileTable::Name
+ "(id_file) ON DELETE CASCADE"
")";
return SqliteTools::executeRequest( connection, req );
return sqlite::Tools::executeRequest( connection, req );
}
bool File::addLabel( LabelPtr label )
......@@ -271,7 +271,7 @@ bool File::addLabel( LabelPtr label )
return false;
}
const char* req = "INSERT INTO LabelFileRelation VALUES(?, ?)";
return SqliteTools::executeRequest( m_dbConnection, req, label->id(), m_id );
return sqlite::Tools::executeRequest( m_dbConnection, req, label->id(), m_id );
}
bool File::removeLabel( LabelPtr label )
......@@ -282,7 +282,7 @@ bool File::removeLabel( LabelPtr label )
return false;
}
const char* req = "DELETE FROM LabelFileRelation WHERE id_label = ? AND id_file = ?";
return SqliteTools::executeDelete( m_dbConnection, req, label->id(), m_id );
return sqlite::Tools::executeDelete( m_dbConnection, req, label->id(), m_id );
}
const std::string& policy::FileCache::key(const std::shared_ptr<File> self )
......@@ -292,5 +292,5 @@ const std::string& policy::FileCache::key(const std::shared_ptr<File> self )
std::string policy::FileCache::key(sqlite3_stmt* stmt)
{
return Traits<std::string>::Load( stmt, 6 );
return sqlite::Traits<std::string>::Load( stmt, 6 );
}
......@@ -5,7 +5,7 @@
#include <sqlite3.h>
#include "IFile.h"
#include "Cache.h"
#include "database/Cache.h"
class Album;
class ShowEpisode;
......
#include "Folder.h"
#include "File.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
namespace policy
{
......@@ -16,7 +16,7 @@ namespace policy
FolderCache::KeyType FolderCache::key( sqlite3_stmt* stmt )
{
return Traits<FolderCache::KeyType>::Load( stmt, 1 );
return sqlite::Traits<FolderCache::KeyType>::Load( stmt, 1 );
}
}
......@@ -24,9 +24,9 @@ namespace policy
Folder::Folder( DBConnection dbConnection, sqlite3_stmt* stmt )
: m_dbConection( dbConnection )
{
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_path = Traits<std::string>::Load( stmt, 1 );
m_parent = Traits<unsigned int>::Load( stmt, 2 );
m_id = sqlite::Traits<unsigned int>::Load( stmt, 0 );
m_path = sqlite::Traits<std::string>::Load( stmt, 1 );
m_parent = sqlite::Traits<unsigned int>::Load( stmt, 2 );
}
Folder::Folder( const std::string& path, unsigned int parent )
......@@ -45,7 +45,7 @@ bool Folder::createTable(DBConnection connection)
"FOREIGN KEY (id_parent) REFERENCES " + policy::FolderTable::Name +
"(id_folder) ON DELETE CASCADE"
")";
return SqliteTools::executeRequest( connection, req );
return sqlite::Tools::executeRequest( connection, req );
}
FolderPtr Folder::create(DBConnection connection, const std::string& path, unsigned int parent )
......@@ -81,7 +81,7 @@ std::vector<FilePtr> Folder::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name +
" WHERE folder_id = ?";
return SqliteTools::fetchAll<File, IFile>( m_dbConection, req, m_id );
return sqlite::Tools::fetchAll<File, IFile>( m_dbConection, req, m_id );
}
FolderPtr Folder::parent()
......@@ -89,5 +89,5 @@ FolderPtr Folder::parent()
//FIXME: use path to be able to fetch from cache?
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name +
" WHERE id_folder = ?";
return SqliteTools::fetchOne<Folder>( m_dbConection, req, m_parent );
return sqlite::Tools::fetchOne<Folder>( m_dbConection, req, m_parent );
}
#pragma once
#include "Cache.h"
#include "database/Cache.h"
#include "IFolder.h"
#include <sqlite3.h>
......
......@@ -4,7 +4,7 @@
#include "Label.h"
#include "File.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
const std::string policy::LabelTable::Name = "Label";
const std::string policy::LabelTable::CacheColumn = "name";
......@@ -38,7 +38,7 @@ std::vector<FilePtr> Label::files()
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
LabelPtr Label::create(DBConnection dbConnection, const std::string& name )
......@@ -57,7 +57,7 @@ bool Label::createTable(DBConnection dbConnection)
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
"name TEXT UNIQUE ON CONFLICT FAIL"
")";
if ( SqliteTools::executeRequest( dbConnection, req ) == false )
if ( sqlite::Tools::executeRequest( dbConnection, req ) == false )
return false;
req = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
"id_label INTEGER,"
......@@ -65,7 +65,7 @@ bool Label::createTable(DBConnection dbConnection)
"PRIMARY KEY (id_label, id_file),"
"FOREIGN KEY(id_label) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(id_file) REFERENCES File(id_file) ON DELETE CASCADE);";
return SqliteTools::executeRequest( dbConnection, req );
return sqlite::Tools::executeRequest( dbConnection, req );
}
const std::string&policy::LabelCachePolicy::key( const std::shared_ptr<ILabel> self )
......@@ -75,5 +75,5 @@ const std::string&policy::LabelCachePolicy::key( const std::shared_ptr<ILabel> s
std::string policy::LabelCachePolicy::key(sqlite3_stmt* stmt)
{
return Traits<KeyType>::Load( stmt, 1 );
return sqlite::Traits<KeyType>::Load( stmt, 1 );
}
......@@ -8,7 +8,7 @@ class File;
class Label;
#include "ILabel.h"
#include "Cache.h"
#include "database/Cache.h"
namespace policy
{
......
......@@ -14,7 +14,7 @@
#include "Parser.h"
#include "Show.h"
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
#include "Utils.h"
#include "VideoTrack.h"
......@@ -71,7 +71,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, std::unique_ptr<factor
if ( res != SQLITE_OK )
return false;
m_dbConnection.reset( dbConnection, &sqlite3_close );
if ( SqliteTools::executeRequest( DBConnection(m_dbConnection), "PRAGMA foreign_keys = ON" ) == false )
if ( sqlite::Tools::executeRequest( DBConnection(m_dbConnection), "PRAGMA foreign_keys = ON" ) == false )
return false;
return ( File::createTable( m_dbConnection ) &&
Folder::createTable( m_dbConnection ) &&
......@@ -192,7 +192,7 @@ AlbumPtr MediaLibrary::album(const std::string& title )
// We can't use Cache helper, since albums are cached by primary keys
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" WHERE title = ?";
return SqliteTools::fetchOne<Album>( DBConnection( m_dbConnection ), req, title );
return sqlite::Tools::fetchOne<Album>( DBConnection( m_dbConnection ), req, title );
}
AlbumPtr MediaLibrary::createAlbum(const std::string& title )
......@@ -204,7 +204,7 @@ ShowPtr MediaLibrary::show(const std::string& name)
{
static const std::string req = "SELECT * FROM " + policy::ShowTable::Name
+ " WHERE name = ?";
return SqliteTools::fetchOne<Show>( m_dbConnection, req, name );
return sqlite::Tools::fetchOne<Show>( m_dbConnection, req, name );
}
ShowPtr MediaLibrary::createShow(const std::string& name)
......@@ -216,7 +216,7 @@ MoviePtr MediaLibrary::movie( const std::string& title )
{
static const std::string req = "SELECT * FROM " + policy::MovieTable::Name
+ " WHERE title = ?";
return SqliteTools::fetchOne<Movie>( m_dbConnection, req, title );
return sqlite::Tools::fetchOne<Movie>( m_dbConnection, req, title );
}
MoviePtr MediaLibrary::createMovie( const std::string& title )
......
#include "Movie.h"
#include "File.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
const std::string policy::MovieTable::Name = "Movie";
const std::string policy::MovieTable::CacheColumn = "id_movie";
......@@ -9,12 +9,12 @@ unsigned int Movie::* const policy::MovieTable::PrimaryKey = &Movie::m_id;
Movie::Movie( DBConnection dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
{
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_title = Traits<std::string>::Load( stmt, 1 );
m_releaseDate = Traits<time_t>::Load( stmt, 2 );
m_summary = Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = Traits<std::string>::Load( stmt, 4 );
m_imdbId = Traits<std::string>::Load( stmt, 5 );
m_id = sqlite::Traits<unsigned int>::Load( stmt, 0 );
m_title = sqlite::Traits<std::string>::Load( stmt, 1 );
m_releaseDate = sqlite::Traits<time_t>::Load( stmt, 2 );
m_summary = sqlite::Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = sqlite::Traits<std::string>::Load( stmt, 4 );
m_imdbId = sqlite::Traits<std::string>::Load( stmt, 5 );
}
Movie::Movie( const std::string& title )
......@@ -44,7 +44,7 @@ bool Movie::setReleaseDate( time_t date )
{
static const std::string req = "UPDATE " + policy::MovieTable::Name
+ " SET release_date = ? WHERE id_movie = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
return false;
m_releaseDate = date;
return true;
......@@ -59,7 +59,7 @@ bool Movie::setShortSummary( const std::string& summary )
{
static const std::string req = "UPDATE " + policy::MovieTable::Name
+ " SET summary = ? WHERE id_movie = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
return false;
m_summary = summary;
return true;
......@@ -74,7 +74,7 @@ bool Movie::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string req = "UPDATE " + policy::MovieTable::Name
+ " SET artwork_url = ? WHERE id_movie = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
......@@ -89,7 +89,7 @@ bool Movie::setImdbId( const std::string& imdbId )
{
static const std::string req = "UPDATE " + policy::MovieTable::Name
+ " SET imdb_id = ? WHERE id_movie = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, imdbId, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, imdbId, m_id ) == false )
return false;
m_imdbId = imdbId;
return true;
......@@ -109,7 +109,7 @@ std::vector<FilePtr> Movie::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE movie_id = ?";
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
bool Movie::createTable( DBConnection dbConnection )
......@@ -123,7 +123,7 @@ bool Movie::createTable( DBConnection dbConnection )
"artwork_url TEXT,"
"imdb_id TEXT"
")";
return SqliteTools::executeRequest( dbConnection, req );
return sqlite::Tools::executeRequest( dbConnection, req );
}
MoviePtr Movie::create(DBConnection dbConnection, const std::string& title )
......
......@@ -3,7 +3,7 @@
#include "IMovie.h"
#include <sqlite3.h>
#include "Cache.h"
#include "database/Cache.h"
class Movie;
......
#include "Show.h"
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
const std::string policy::ShowTable::Name = "Show";
const std::string policy::ShowTable::CacheColumn = "id_show";
......@@ -9,13 +9,13 @@ unsigned int Show::* const policy::ShowTable::PrimaryKey = &Show::m_id;
Show::Show(DBConnection dbConnection, sqlite3_stmt* stmt)
: m_dbConnection( dbConnection )
{
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_name = Traits<std::string>::Load( stmt, 1 );
m_releaseDate = Traits<unsigned int>::Load( stmt, 2 );
m_shortSummary = Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = Traits<std::string>::Load( stmt, 4 );
m_lastSyncDate = Traits<unsigned int>::Load( stmt, 5 );
m_tvdbId = Traits<std::string>::Load( stmt, 6 );
m_id = sqlite::Traits<unsigned int>::Load( stmt, 0 );
m_name = sqlite::Traits<std::string>::Load( stmt, 1 );
m_releaseDate = sqlite::Traits<unsigned int>::Load( stmt, 2 );
m_shortSummary = sqlite::Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = sqlite::Traits<std::string>::Load( stmt, 4 );
m_lastSyncDate = sqlite::Traits<unsigned int>::Load( stmt, 5 );
m_tvdbId = sqlite::Traits<std::string>::Load( stmt, 6 );
}
Show::Show( const std::string& name )
......@@ -45,7 +45,7 @@ bool Show::setReleaseDate( time_t date )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET release_date = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
return false;
m_releaseDate = date;
return true;
......@@ -60,7 +60,7 @@ bool Show::setShortSummary( const std::string& summary )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET short_summary = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
return false;
m_shortSummary = summary;
return true;
......@@ -75,7 +75,7 @@ bool Show::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET artwork_url = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
......@@ -95,7 +95,7 @@ bool Show::setTvdbId( const std::string& tvdbId )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET tvdb_id = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, tvdbId, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, tvdbId, m_id ) == false )
return false;
m_tvdbId = tvdbId;
return true;
......@@ -110,7 +110,7 @@ std::vector<ShowEpisodePtr> Show::episodes()
{
static const std::string req = "SELECT * FROM " + policy::ShowEpisodeTable::Name
+ " WHERE show_id = ?";
return SqliteTools::fetchAll<ShowEpisode, IShowEpisode>( m_dbConnection, req, m_id );
return sqlite::Tools::fetchAll<ShowEpisode, IShowEpisode>( m_dbConnection, req, m_id );
}
bool Show::destroy()
......@@ -135,7 +135,7 @@ bool Show::createTable(DBConnection dbConnection)
"last_sync_date UNSIGNED INTEGER,"
"tvdb_id TEXT"
")";
return SqliteTools::executeRequest( dbConnection, req );
return sqlite::Tools::executeRequest( dbConnection, req );
}
ShowPtr Show::create(DBConnection dbConnection, const std::string& name )
......
......@@ -3,7 +3,7 @@
#include <sqlite3.h>
#include "Cache.h"
#include "database/Cache.h"
#include "IMediaLibrary.h"
#include "IShow.h"
......
#include "ShowEpisode.h"
#include "SqliteTools.h"
#include "database/SqliteTools.h"
#include "Show.h"
#include "File.h"
......@@ -10,15 +10,15 @@ unsigned int ShowEpisode::* const policy::ShowEpisodeTable::PrimaryKey = &ShowEp
ShowEpisode::ShowEpisode( DBConnection dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
{
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_artworkUrl = Traits<std::string>::Load( stmt, 1 );
m_episodeNumber = Traits<unsigned int>::Load( stmt, 2 );
m_lastSyncDate = Traits<time_t>::Load( stmt, 3 );
m_name = Traits<std::string>::Load( stmt, 4 );
m_seasonNumber = Traits<unsigned int>::Load( stmt, 5 );
m_shortSummary = Traits<std::string>::Load( stmt, 6 );
m_tvdbId = Traits<std::string>::Load( stmt, 7 );
m_showId = Traits<unsigned int>::Load( stmt, 8 );
m_id = sqlite::Traits<unsigned int>::Load( stmt, 0 );
m_artworkUrl = sqlite::Traits<std::string>::Load( stmt, 1 );
m_episodeNumber = sqlite::Traits<unsigned int>::Load( stmt, 2 );
m_lastSyncDate = sqlite::Traits<time_t>::Load( stmt, 3 );
m_name = sqlite::Traits<std::string>::Load( stmt, 4 );
m_seasonNumber = sqlite::Traits<unsigned int>::Load( stmt, 5 );
m_shortSummary = sqlite::Traits<std::string>::Load( stmt, 6 );
m_tvdbId = sqlite::Traits<std::string>::Load( stmt, 7 );
m_showId = sqlite::Traits<unsigned int>::Load( stmt, 8 );
}
ShowEpisode::ShowEpisode( const std::string& name, unsigned int episodeNumber, unsigned int showId )
......@@ -44,7 +44,7 @@ bool ShowEpisode::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string req = "UPDATE " + policy::ShowEpisodeTable::Name
+ " SET artwork_url = ? WHERE id_episode = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
......@@ -74,7 +74,7 @@ bool ShowEpisode::setSeasonNumber( unsigned int seasonNumber )
{
static const std::string req = "UPDATE " + policy::ShowEpisodeTable::Name