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

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;
......
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