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

SqliteTools: Rename insert -> executeInsert

So that it matches the other request helpers naming scheme
parent cb6aae75
......@@ -311,7 +311,7 @@ bool Album::addArtist( std::shared_ptr<Artist> artist )
LOG_ERROR("Both artist & album need to be inserted in database before being linked together" );
return false;
}
return sqlite::Tools::insert( m_ml->getConn(), req, m_id, artist->id() ) != 0;
return sqlite::Tools::executeInsert( m_ml->getConn(), req, m_id, artist->id() ) != 0;
}
bool Album::removeArtist(Artist* artist)
......
......@@ -114,7 +114,7 @@ bool Artist::addMedia( Media& media )
static const std::string req = "INSERT INTO MediaArtistRelation VALUES(?, ?)";
// If track's ID is 0, the request will fail due to table constraints
sqlite::ForeignKey artistForeignKey( m_id );
return sqlite::Tools::insert( m_ml->getConn(), req, media.id(), artistForeignKey ) != 0;
return sqlite::Tools::executeInsert( m_ml->getConn(), req, media.id(), artistForeignKey ) != 0;
}
const std::string& Artist::artworkMrl() const
......@@ -244,7 +244,7 @@ bool Artist::createDefaultArtists( DBConnection dbConnection )
// This will skip the cache for those new entities, but they will be inserted soon enough anyway.
static const std::string req = "INSERT OR IGNORE INTO " + policy::ArtistTable::Name +
"(id_artist) VALUES(?),(?)";
sqlite::Tools::insert( dbConnection, req, medialibrary::UnknownArtistID,
sqlite::Tools::executeInsert( dbConnection, req, medialibrary::UnknownArtistID,
medialibrary::VariousArtistID );
// Always return true. The insertion might succeed, but we consider it a failure when 0 row
// gets inserted, while we are explicitely specifying "OR IGNORE" here.
......
......@@ -134,7 +134,7 @@ bool Folder::blacklist( MediaLibraryPtr ml, const std::string& fullPath )
path = fullPath;
static const std::string req = "INSERT INTO " + policy::FolderTable::Name +
"(path, parent_id, is_blacklisted, device_id, is_removable) VALUES(?, ?, ?, ?, ?)";
return sqlite::Tools::insert( ml->getConn(), req, path, nullptr, true, device->id(), deviceFs->isRemovable() ) != 0;
return sqlite::Tools::executeInsert( ml->getConn(), req, path, nullptr, true, device->id(), deviceFs->isRemovable() ) != 0;
}
void Folder::setFileSystemFactory( std::shared_ptr<factory::IFileSystem> fsFactory )
......
......@@ -72,7 +72,7 @@ bool History::insert( DBConnection dbConn, const std::string& mrl )
" UNION SELECT NULL, ?, NULL, NULL"
" ORDER BY id_record DESC"
" LIMIT 1";
return sqlite::Tools::insert( dbConn, req, mrl, mrl ) != 0;
return sqlite::Tools::executeInsert( dbConn, req, mrl, mrl ) != 0;
}
std::vector<std::shared_ptr<IHistoryEntry> > History::fetch( MediaLibraryPtr ml )
......
......@@ -501,7 +501,7 @@ bool Media::addLabel( LabelPtr label )
return false;
}
const char* req = "INSERT INTO LabelFileRelation VALUES(?, ?)";
if ( sqlite::Tools::insert( m_ml->getConn(), req, label->id(), m_id ) == 0 )
if ( sqlite::Tools::executeInsert( m_ml->getConn(), req, label->id(), m_id ) == 0 )
return false;
const std::string reqFts = "UPDATE " + policy::MediaTable::Name + "Fts "
"SET labels = labels || ' ' || ? WHERE rowid = ?";
......
......@@ -102,7 +102,7 @@ bool Playlist::add( int64_t mediaId, unsigned int position )
static const std::string req = "INSERT INTO PlaylistMediaRelation(media_id, playlist_id, position) VALUES(?, ?, ?)";
// position isn't a foreign key, but we want it to be passed as NULL if it equals to 0
// When the position is NULL, the insertion triggers takes care of counting the number of records to auto append.
return sqlite::Tools::insert( m_ml->getConn(), req, mediaId, m_id, sqlite::ForeignKey{ position } );
return sqlite::Tools::executeInsert( m_ml->getConn(), req, mediaId, m_id, sqlite::ForeignKey{ position } );
}
bool Playlist::move( int64_t mediaId, unsigned int position )
......
......@@ -39,7 +39,7 @@ bool Settings::load( DBConnection dbConn )
// First launch: no settings
if ( row == nullptr )
{
if ( sqlite::Tools::insert( m_dbConn, "INSERT INTO Settings VALUES(?)", MediaLibrary::DbModelVersion ) == false )
if ( sqlite::Tools::executeInsert( m_dbConn, "INSERT INTO Settings VALUES(?)", MediaLibrary::DbModelVersion ) == false )
return false;
m_dbModelVersion = MediaLibrary::DbModelVersion;
}
......
......@@ -109,7 +109,7 @@ class DatabaseHelpers
template <typename... Args>
static bool insert( MediaLibraryPtr ml, std::shared_ptr<IMPL> self, const std::string& req, Args&&... args )
{
int64_t pKey = sqlite::Tools::insert( ml->getConn(), req, std::forward<Args>( args )... );
int64_t pKey = sqlite::Tools::executeInsert( ml->getConn(), req, std::forward<Args>( args )... );
if ( pKey == 0 )
return false;
Lock l{ Mutex };
......
......@@ -277,7 +277,7 @@ class Tools
* Returns 0 (which is an invalid sqlite primary key) when insertion fails.
*/
template <typename... Args>
static int64_t insert( DBConnection dbConnection, const std::string& req, Args&&... args )
static int64_t executeInsert( DBConnection dbConnection, const std::string& req, Args&&... args )
{
SqliteConnection::WriteContext ctx;
if (Transaction::transactionInProgress() == false)
......
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