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

sqlite::Tools::executeRequest never returns false

parent 4dc66dfc
......@@ -331,7 +331,7 @@ bool Album::removeArtist(Artist* artist)
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id, artist->id() );
}
bool Album::createTable( sqlite::Connection* dbConnection )
void Album::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::AlbumTable::Name +
......@@ -364,13 +364,13 @@ bool Album::createTable( sqlite::Connection* dbConnection )
")";
const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_artist_id_idx ON " +
policy::AlbumTable::Name + "(artist_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, reqRel ) &&
sqlite::Tools::executeRequest( dbConnection, vtableReq ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, reqRel );
sqlite::Tools::executeRequest( dbConnection, vtableReq );
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
bool Album::createTriggers( sqlite::Connection* dbConnection )
void Album::createTriggers( sqlite::Connection* dbConnection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_album_present AFTER UPDATE OF "
"is_present ON " + policy::AlbumTrackTable::Name +
......@@ -415,11 +415,11 @@ bool Album::createTriggers( sqlite::Connection* dbConnection )
" BEGIN"
" DELETE FROM " + policy::AlbumTable::Name + "Fts WHERE rowid = old.id_album;"
" END";
return sqlite::Tools::executeRequest( dbConnection, triggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, deleteTriggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, updateAddTrackTriggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, vtriggerInsert ) &&
sqlite::Tools::executeRequest( dbConnection, vtriggerDelete );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, deleteTriggerReq );
sqlite::Tools::executeRequest( dbConnection, updateAddTrackTriggerReq );
sqlite::Tools::executeRequest( dbConnection, vtriggerInsert );
sqlite::Tools::executeRequest( dbConnection, vtriggerDelete );
}
std::shared_ptr<Album> Album::create( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl )
......
......@@ -98,8 +98,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
bool addArtist( std::shared_ptr<Artist> artist );
bool removeArtist( Artist* artist );
static bool createTable( sqlite::Connection* dbConnection );
static bool createTriggers( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static void createTriggers( sqlite::Connection* dbConnection );
static std::shared_ptr<Album> create( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl );
static std::shared_ptr<Album> createUnknownAlbum( MediaLibraryPtr ml, const Artist* artist );
///
......
......@@ -98,7 +98,7 @@ bool AlbumTrack::setArtist( std::shared_ptr<Artist> artist )
return true;
}
bool AlbumTrack::createTable( sqlite::Connection* dbConnection )
void AlbumTrack::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -130,9 +130,9 @@ bool AlbumTrack::createTable( sqlite::Connection* dbConnection )
policy::AlbumTrackTable::Name +
"(media_id, artist_id, genre_id, album_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, triggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, int64_t albumId,
......
......@@ -68,7 +68,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
virtual std::shared_ptr<IAlbum> album() override;
virtual std::shared_ptr<IMedia> media() override;
static bool createTable( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<AlbumTrack> create(MediaLibraryPtr ml, int64_t albumId,
std::shared_ptr<Media> media, unsigned int trackNb,
unsigned int discNumber, int64_t artistId, int64_t genreId,
......
......@@ -189,7 +189,7 @@ bool Artist::setMusicBrainzId( const std::string& mbId )
return true;
}
bool Artist::createTable( sqlite::Connection* dbConnection )
void Artist::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::ArtistTable::Name +
......@@ -215,12 +215,12 @@ bool Artist::createTable( sqlite::Connection* dbConnection )
policy::ArtistTable::Name + "Fts USING FTS3("
"name"
")";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, reqRel ) &&
sqlite::Tools::executeRequest( dbConnection, reqFts );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, reqRel );
sqlite::Tools::executeRequest( dbConnection, reqFts );
}
bool Artist::createTriggers( sqlite::Connection* dbConnection )
void Artist::createTriggers( sqlite::Connection* dbConnection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS has_album_present AFTER UPDATE OF "
"is_present ON " + policy::AlbumTable::Name +
......@@ -258,10 +258,10 @@ bool Artist::createTriggers( sqlite::Connection* dbConnection )
" BEGIN"
" DELETE FROM " + policy::ArtistTable::Name + "Fts WHERE rowid=old.id_artist;"
" END";
return sqlite::Tools::executeRequest( dbConnection, triggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, autoDeleteTriggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, ftsInsertTrigger ) &&
sqlite::Tools::executeRequest( dbConnection, ftsDeleteTrigger );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, autoDeleteTriggerReq );
sqlite::Tools::executeRequest( dbConnection, ftsInsertTrigger );
sqlite::Tools::executeRequest( dbConnection, ftsDeleteTrigger );
}
bool Artist::createDefaultArtists( sqlite::Connection* dbConnection )
......
......@@ -63,8 +63,8 @@ public:
virtual const std::string& musicBrainzId() const override;
bool setMusicBrainzId( const std::string& musicBrainzId );
static bool createTable( sqlite::Connection* dbConnection );
static bool createTriggers( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static void createTriggers( sqlite::Connection* dbConnection );
static bool createDefaultArtists( sqlite::Connection* dbConnection );
static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
static std::vector<ArtistPtr> search( MediaLibraryPtr ml, const std::string& name );
......
......@@ -97,7 +97,7 @@ const std::string& AudioTrack::description() const
return m_description;
}
bool AudioTrack::createTable( sqlite::Connection* dbConnection )
void AudioTrack::createTable( sqlite::Connection* dbConnection )
{
//FIXME: Index on media_id ? Unless it's already implied by the foreign key
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AudioTrackTable::Name
......@@ -115,8 +115,8 @@ bool AudioTrack::createTable( sqlite::Connection* dbConnection )
")";
const std::string indexReq = "CREATE INDEX IF NOT EXISTS audio_track_media_idx ON " +
policy::AudioTrackTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<AudioTrack> AudioTrack::create( MediaLibraryPtr ml, const std::string& codec,
......
......@@ -58,7 +58,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy
virtual const std::string& language() const override;
virtual const std::string& description() const override;
static bool createTable( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<AudioTrack> create( MediaLibraryPtr ml, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc, int64_t mediaId );
......
......@@ -100,7 +100,7 @@ std::shared_ptr<Device> Device::create( MediaLibraryPtr ml, const std::string& u
return self;
}
bool Device::createTable( sqlite::Connection* connection )
void Device::createTable( sqlite::Connection* connection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::DeviceTable::Name + "("
"id_device INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -109,7 +109,7 @@ bool Device::createTable( sqlite::Connection* connection )
"is_removable BOOLEAN,"
"is_present BOOLEAN"
")";
return sqlite::Tools::executeRequest( connection, req );
sqlite::Tools::executeRequest( connection, req );
}
std::shared_ptr<Device> Device::fromUuid( MediaLibraryPtr ml, const std::string& uuid )
......
......@@ -59,7 +59,7 @@ public:
const std::string& scheme() const;
static std::shared_ptr<Device> create( MediaLibraryPtr ml, const std::string& uuid, const std::string& scheme, bool isRemovable );
static bool createTable( sqlite::Connection* connection );
static void createTable( sqlite::Connection* connection );
static std::shared_ptr<Device> fromUuid( MediaLibraryPtr ml, const std::string& uuid );
private:
......
......@@ -190,7 +190,7 @@ int64_t File::folderId()
return m_folderId;
}
bool File::createTable( sqlite::Connection* dbConnection )
void File::createTable( sqlite::Connection* dbConnection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
"id_file INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -223,10 +223,10 @@ bool File::createTable( sqlite::Connection* dbConnection )
policy::FileTable::Name + "(media_id)";
std::string folderIndexReq = "CREATE INDEX IF NOT EXISTS file_folder_id_index ON " +
policy::FileTable::Name + "(folder_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, triggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, mediaIndexReq ) &&
sqlite::Tools::executeRequest( dbConnection, folderIndexReq );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, mediaIndexReq );
sqlite::Tools::executeRequest( dbConnection, folderIndexReq );
}
std::shared_ptr<File> File::createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type, const fs::IFile& fileFs,
......
......@@ -77,7 +77,7 @@ public:
bool destroy();
int64_t folderId();
static bool createTable( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
const fs::IFile& file, int64_t folderId, bool isRemovable );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
......
......@@ -70,7 +70,7 @@ Folder::Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent, int6
{
}
bool Folder::createTable( sqlite::Connection* connection)
void Folder::createTable( sqlite::Connection* connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FolderTable::Name +
"("
......@@ -102,11 +102,11 @@ bool Folder::createTable( sqlite::Connection* connection)
policy::FolderTable::Name + " (device_id)";
std::string parentFolderIndexReq = "CREATE INDEX IF NOT EXISTS parent_folder_id_idx ON " +
policy::FolderTable::Name + " (parent_id)";
return sqlite::Tools::executeRequest( connection, req ) &&
sqlite::Tools::executeRequest( connection, exclEntryReq ) &&
sqlite::Tools::executeRequest( connection, triggerReq ) &&
sqlite::Tools::executeRequest( connection, deviceIndexReq ) &&
sqlite::Tools::executeRequest( connection, parentFolderIndexReq );
sqlite::Tools::executeRequest( connection, req );
sqlite::Tools::executeRequest( connection, exclEntryReq );
sqlite::Tools::executeRequest( connection, triggerReq );
sqlite::Tools::executeRequest( connection, deviceIndexReq );
sqlite::Tools::executeRequest( connection, parentFolderIndexReq );
}
std::shared_ptr<Folder> Folder::create( MediaLibraryPtr ml, const std::string& mrl,
......
......@@ -60,7 +60,7 @@ public:
Folder( MediaLibraryPtr ml, sqlite::Row& row );
Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent , int64_t deviceId , bool isRemovable );
static bool createTable( sqlite::Connection* connection );
static void createTable( sqlite::Connection* connection );
static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& mrl, int64_t parentId, Device& device, fs::IDevice& deviceFs );
static void excludeEntryFolder( MediaLibraryPtr ml, int64_t folderId );
static bool blacklist( MediaLibraryPtr ml, const std::string& mrl );
......
......@@ -97,7 +97,7 @@ std::vector<AlbumPtr> Genre::albums( SortingCriteria sort, bool desc ) const
return Album::fromGenre( m_ml, m_id, sort, desc );
}
bool Genre::createTable( sqlite::Connection* dbConn )
void Genre::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::GenreTable::Name +
"("
......@@ -120,13 +120,13 @@ bool Genre::createTable( sqlite::Connection* dbConn )
" BEGIN"
" DELETE FROM " + policy::GenreTable::Name + "Fts WHERE rowid = old.id_genre;"
" END";
return sqlite::Tools::executeRequest( dbConn, req ) &&
sqlite::Tools::executeRequest( dbConn, vtableReq ) &&
sqlite::Tools::executeRequest( dbConn, vtableInsertTrigger ) &&
sqlite::Tools::executeRequest( dbConn, vtableDeleteTrigger );
sqlite::Tools::executeRequest( dbConn, req );
sqlite::Tools::executeRequest( dbConn, vtableReq );
sqlite::Tools::executeRequest( dbConn, vtableInsertTrigger );
sqlite::Tools::executeRequest( dbConn, vtableDeleteTrigger );
}
bool Genre::createTriggers( sqlite::Connection* dbConn )
void Genre::createTriggers( sqlite::Connection* dbConn )
{
const std::string onGenreChanged = "CREATE TRIGGER IF NOT EXISTS on_track_genre_changed AFTER UPDATE OF "
" genre_id ON " + policy::AlbumTrackTable::Name +
......@@ -149,9 +149,9 @@ bool Genre::createTriggers( sqlite::Connection* dbConn )
" DELETE FROM " + policy::GenreTable::Name + " WHERE nb_tracks = 0;"
" END";
return sqlite::Tools::executeRequest( dbConn, onGenreChanged ) &&
sqlite::Tools::executeRequest( dbConn, onTrackCreated ) &&
sqlite::Tools::executeRequest( dbConn, onTrackDeleted );
sqlite::Tools::executeRequest( dbConn, onGenreChanged );
sqlite::Tools::executeRequest( dbConn, onTrackCreated );
sqlite::Tools::executeRequest( dbConn, onTrackDeleted );
}
std::shared_ptr<Genre> Genre::create( MediaLibraryPtr ml, const std::string& name )
......
......@@ -54,8 +54,8 @@ public:
virtual std::vector<MediaPtr> tracks(SortingCriteria sort, bool desc) const override;
virtual std::vector<AlbumPtr> albums( SortingCriteria sort, bool desc ) const override;
static bool createTable( sqlite::Connection* dbConn );
static bool createTriggers( sqlite::Connection* dbConn );
static void createTable( sqlite::Connection* dbConn );
static void createTriggers( sqlite::Connection* dbConn );
static std::shared_ptr<Genre> create( MediaLibraryPtr ml, const std::string& name );
static std::shared_ptr<Genre> fromName( MediaLibraryPtr ml, const std::string& name );
static std::vector<GenrePtr> search( MediaLibraryPtr ml, const std::string& name );
......
......@@ -49,7 +49,7 @@ History::History( MediaLibraryPtr ml, sqlite::Row& row )
row >> m_date;
}
bool History::createTable( sqlite::Connection* dbConnection )
void History::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::HistoryTable::Name +
"("
......@@ -66,8 +66,8 @@ bool History::createTable( sqlite::Connection* dbConnection )
" ORDER BY insertion_date DESC LIMIT -1 OFFSET " + std::to_string( MaxEntries ) + ");"
" END";
// Don't index the id_media field, we don't want to select history records using the media_id
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
bool History::insert( sqlite::Connection* dbConn, int64_t mediaId )
......@@ -85,10 +85,10 @@ std::vector<HistoryPtr> History::fetch( MediaLibraryPtr ml )
return fetchAll<IHistoryEntry>( ml, req );
}
bool History::clearStreams( MediaLibraryPtr ml )
void History::clearStreams( MediaLibraryPtr ml )
{
static const std::string req = "DELETE FROM " + policy::HistoryTable::Name;
return sqlite::Tools::executeRequest( ml->getConn(), req );
sqlite::Tools::executeRequest( ml->getConn(), req );
}
MediaPtr History::media() const
......
......@@ -49,10 +49,10 @@ class History : public IHistoryEntry, public DatabaseHelpers<History, policy::Hi
{
public:
History( MediaLibraryPtr ml, sqlite::Row& row );
static bool createTable( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static bool insert( sqlite::Connection* dbConn, int64_t mediaId );
static std::vector<HistoryPtr> fetch( MediaLibraryPtr ml );
static bool clearStreams( MediaLibraryPtr ml );
static void clearStreams( MediaLibraryPtr ml );
virtual MediaPtr media() const override;
virtual unsigned int insertionDate() const override;
......
......@@ -80,7 +80,7 @@ LabelPtr Label::create( MediaLibraryPtr ml, const std::string& name )
return self;
}
bool Label::createTable( sqlite::Connection* dbConnection )
void Label::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
......@@ -98,9 +98,9 @@ bool Label::createTable( sqlite::Connection* dbConnection )
" UPDATE " + policy::MediaTable::Name + "Fts SET labels = TRIM(REPLACE(labels, old.name, ''))"
" WHERE labels MATCH old.name;"
" END";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, relReq ) &&
sqlite::Tools::executeRequest( dbConnection, ftsTrigger );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, relReq );
sqlite::Tools::executeRequest( dbConnection, ftsTrigger );
}
}
......@@ -57,7 +57,7 @@ class Label : public ILabel, public DatabaseHelpers<Label, policy::LabelTable>
virtual std::vector<MediaPtr> files() override;
static LabelPtr create( MediaLibraryPtr ml, const std::string& name );
static bool createTable( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
private:
MediaLibraryPtr m_ml;
......
......@@ -514,7 +514,7 @@ void Media::setTitleBuffered( const std::string& title )
m_changed = true;
}
bool Media::createTable( sqlite::Connection* connection )
void Media::createTable( sqlite::Connection* connection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MediaTable::Name + "("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -544,13 +544,13 @@ bool Media::createTable( sqlite::Connection* connection )
"value TEXT,"
"PRIMARY KEY (id_media, type)"
")";
return sqlite::Tools::executeRequest( connection, req ) &&
sqlite::Tools::executeRequest( connection, indexReq ) &&
sqlite::Tools::executeRequest( connection, vtableReq ) &&
sqlite::Tools::executeRequest( connection, metadataReq );
sqlite::Tools::executeRequest( connection, req );
sqlite::Tools::executeRequest( connection, indexReq );
sqlite::Tools::executeRequest( connection, vtableReq );
sqlite::Tools::executeRequest( connection, metadataReq );
}
bool Media::createTriggers( sqlite::Connection* connection )
void Media::createTriggers( sqlite::Connection* connection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS has_files_present AFTER UPDATE OF "
"is_present ON " + policy::FileTable::Name +
......@@ -585,11 +585,11 @@ bool Media::createTriggers( sqlite::Connection* connection )
" BEGIN"
" UPDATE " + policy::MediaTable::Name + "Fts SET title = new.title WHERE rowid = new.id_media;"
" END";
return sqlite::Tools::executeRequest( connection, triggerReq ) &&
sqlite::Tools::executeRequest( connection, triggerReq2 ) &&
sqlite::Tools::executeRequest( connection, vtableInsertTrigger ) &&
sqlite::Tools::executeRequest( connection, vtableDeleteTrigger ) &&
sqlite::Tools::executeRequest( connection, vtableUpdateTitleTrigger2 );
sqlite::Tools::executeRequest( connection, triggerReq );
sqlite::Tools::executeRequest( connection, triggerReq2 );
sqlite::Tools::executeRequest( connection, vtableInsertTrigger );
sqlite::Tools::executeRequest( connection, vtableDeleteTrigger );
sqlite::Tools::executeRequest( connection, vtableUpdateTitleTrigger2 );
}
bool Media::addLabel( LabelPtr label )
......
......@@ -85,8 +85,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
Media( MediaLibraryPtr ml, const std::string& title, Type type);
static std::shared_ptr<Media> create( MediaLibraryPtr ml, Type type, const std::string& fileName );
static bool createTable( sqlite::Connection* connection );
static bool createTriggers( sqlite::Connection* connection );
static void createTable( sqlite::Connection* connection );
static void createTriggers( sqlite::Connection* connection );
virtual int64_t id() const override;
virtual Type type() override;
......
......@@ -131,7 +131,7 @@ void MediaLibrary::clearCache()
Genre::clear();
}
bool MediaLibrary::createAllTables()
void MediaLibrary::createAllTables()
{
// We need to create the tables in order of triggers creation
// Device is the "root of all evil". When a device is modified,
......@@ -139,33 +139,30 @@ bool MediaLibrary::createAllTables()
// an update on files, and so on.
auto t = m_dbConnection->newTransaction();
auto res = Device::createTable( m_dbConnection.get() ) &&
Folder::createTable( m_dbConnection.get() ) &&
Media::createTable( m_dbConnection.get() ) &&
File::createTable( m_dbConnection.get() ) &&
Label::createTable( m_dbConnection.get() ) &&
Playlist::createTable( m_dbConnection.get() ) &&
Genre::createTable( m_dbConnection.get() ) &&
Album::createTable( m_dbConnection.get() ) &&
AlbumTrack::createTable( m_dbConnection.get() ) &&
Album::createTriggers( m_dbConnection.get() ) &&
Show::createTable( m_dbConnection.get() ) &&
ShowEpisode::createTable( m_dbConnection.get() ) &&
Movie::createTable( m_dbConnection.get() ) &&
VideoTrack::createTable( m_dbConnection.get() ) &&
AudioTrack::createTable( m_dbConnection.get() ) &&
Artist::createTable( m_dbConnection.get() ) &&
Artist::createDefaultArtists( m_dbConnection.get() ) &&
Artist::createTriggers( m_dbConnection.get() ) &&
Media::createTriggers( m_dbConnection.get() ) &&
Genre::createTriggers( m_dbConnection.get() ) &&
Playlist::createTriggers( m_dbConnection.get() ) &&
History::createTable( m_dbConnection.get() ) &&
Settings::createTable( m_dbConnection.get() );
if ( res == false )
return false;
Device::createTable( m_dbConnection.get() );
Folder::createTable( m_dbConnection.get() );
Media::createTable( m_dbConnection.get() );
File::createTable( m_dbConnection.get() );
Label::createTable( m_dbConnection.get() );
Playlist::createTable( m_dbConnection.get() );
Genre::createTable( m_dbConnection.get() );
Album::createTable( m_dbConnection.get() );
AlbumTrack::createTable( m_dbConnection.get() );
Album::createTriggers( m_dbConnection.get() );
Show::createTable( m_dbConnection.get() );
ShowEpisode::createTable( m_dbConnection.get() );
Movie::createTable( m_dbConnection.get() );
VideoTrack::createTable( m_dbConnection.get() );
AudioTrack::createTable( m_dbConnection.get() );
Artist::createTable( m_dbConnection.get() );
Artist::createDefaultArtists( m_dbConnection.get() );
Artist::createTriggers( m_dbConnection.get() );
Media::createTriggers( m_dbConnection.get() );
Genre::createTriggers( m_dbConnection.get() );
Playlist::createTriggers( m_dbConnection.get() );
History::createTable( m_dbConnection.get() );
Settings::createTable( m_dbConnection.get() );
t->commit();
return true;
}
template <typename T>
......@@ -277,11 +274,7 @@ InitializeResult MediaLibrary::initialize( const std::string& dbPath,
auto res = InitializeResult::Success;
try
{
if ( createAllTables() == false )
{
LOG_ERROR( "Failed to create database structure" );
return InitializeResult::Failed;
}
createAllTables();
if ( m_settings.load() == false )
{
LOG_ERROR( "Failed to load settings" );
......@@ -635,8 +628,7 @@ bool MediaLibrary::clearHistory()
return sqlite::Tools::withRetries( 3, [this]() {
auto t = getConn()->newTransaction();
Media::clearHistory( this );
if ( History::clearStreams( this ) == false )
return false;
History::clearStreams( this );
t->commit();
return true;
});
......@@ -846,8 +838,7 @@ bool MediaLibrary::recreateDatabase( const std::string& dbPath )
m_dbConnection.reset();
unlink( dbPath.c_str() );
m_dbConnection = sqlite::Connection::connect( dbPath );
if ( createAllTables() == false )
return false;
createAllTables();
// We dropped the database, there is no setting to be read anymore
if( m_settings.load() == false )
return false;
......@@ -870,10 +861,7 @@ bool MediaLibrary::migrateModel3to5()
};
for ( const auto& req : reqs )
{
if ( sqlite::Tools::executeRequest( getConn(), req ) == false )
return false;
}
sqlite::Tools::executeRequest( getConn(), req );
// Re-create triggers removed in the process
Media::createTriggers( getConn() );
Playlist::createTriggers( getConn() );
......@@ -890,10 +878,7 @@ bool MediaLibrary::migrateModel5to6()
# include "database/migrations/migration5-6.sql"
};
for ( const auto& req : reqs )
{
if ( sqlite::Tools::executeRequest( getConn(), req ) == false )
return false;
}
sqlite::Tools::executeRequest( getConn(), req );
t->commit();
return true;
}
......@@ -907,8 +892,7 @@ bool MediaLibrary::migrateModel6to7()
// This needs to be done from outside of the weak context, as we want
// triggers & foreign key to be enforced.
std::string req = "DELETE FROM " + policy::MediaTable::Name + " WHERE type = 0";
if ( sqlite::Tools::executeRequest( conn, req ) == false )
return false;
sqlite::Tools::executeRequest( conn, req );
auto oldGenres = genres( SortingCriteria::Default, false );
......@@ -919,10 +903,7 @@ bool MediaLibrary::migrateModel6to7()
# include "database/migrations/migration6-7.sql"
};
for ( const auto& req : reqs )
{
if ( sqlite::Tools::executeRequest( conn, req ) == false )
return false;
}
sqlite::Tools::executeRequest( conn, req );
// Clear the genres that were inserted in the cache when fetching oldGenres
Genre::clear();
// Since the ID might change, we need to keep track of newly inserted
......
......@@ -168,7 +168,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
bool migrateModel3to5();
bool migrateModel5to6();
bool migrateModel6to7();
bool createAllTables();
void createAllTables();
void registerEntityHooks();
static bool validateSearchPattern( const std::string& pattern );
// Returns true if the device actually changed
......
......@@ -116,7 +116,7 @@ std::vector<MediaPtr> Movie::files()
return Media::fetchAll<IMedia>( m_ml, req, m_id );
}
bool Movie::createTable( sqlite::Connection* dbConnection )
void Movie::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MovieTable::Name
+ "("
......@@ -131,8 +131,8 @@ bool Movie::createTable( sqlite::Connection* dbConnection )
")";
const std::string indexReq = "CREATE INDEX IF NOT EXISTS movie_media_idx ON " +
policy::MovieTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
sqlite::Tools::executeRequest( dbConnection, req );
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<Movie> Movie::create(MediaLibraryPtr ml, int64_t mediaId, const std::string& title )
......
......@@ -58,7 +58,7 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
bool setImdbId(const std::string& imdbId);
virtual std::vector<MediaPtr> files() override;
static bool createTable( sqlite::Connection* dbConnection );
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Movie> create( MediaLibraryPtr ml, int64_t mediaId, const std::string& title );
static MoviePtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
......
......@@ -178,7 +178,7 @@ bool Playlist::remove( int64_t mediaId )
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id, mediaId );
}
bool Playlist::createTable( sqlite::Connection* dbConn )
void Playlist::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -204,12 +204,12 @@ bool Playlist::createTable( sqlite::Connection* dbConn )
"name"
")";
//FIXME Enforce (playlist_id,position) uniqueness
return sqlite::Tools::executeRequest( dbConn, req ) &&
sqlite::Tools::executeRequest( dbConn, relTableReq ) &&
sqlite::Tools::executeRequest( dbConn, vtableReq );
sqlite::Tools::executeRequest( dbConn, req );
sqlite::Tools::executeRequest( dbConn, relTableReq );
sqlite::Tools::executeRequest( dbConn, vtableReq );
}
bool Playlist::createTriggers( sqlite::Connection* dbConn )
void Playlist::createTriggers( sqlite::Connection* dbConn )
{
static const std::string req = "CREATE TRIGGER IF NOT EXISTS update_playlist_order AFTER UPDATE OF position"
" ON PlaylistMediaRelation"
......@@ -252,12 +252,12 @@ bool Playlist::createTriggers( sqlite::Connection* dbConn )
" BEGIN"
" DELETE FROM " + policy::PlaylistTable::Name + "Fts WHERE rowid = old.id_playlist;"
" END";
return sqlite::Tools::executeRequest( dbConn, req ) &&
sqlite::Tools::executeRequest( dbConn, autoAppendReq ) &&
sqlite::Tools::executeRequest( dbConn, autoShiftPosReq ) &&
sqlite::Tools::executeRequest( dbConn, vtriggerInsert ) &&
sqlite::Tools::executeRequest( dbConn, vtriggerUpdate ) &&
sqlite::Tools::executeRequest( dbConn, vtriggerDelete );
sqlite::Tools::executeRequest( dbConn, req );