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

sqlite: Add an executeInsert helper

Even though it does exactly the same as as executeUpdate/executeDelete,
it improves clarity
parent e94fcd7c
......@@ -225,7 +225,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::executeRequest( m_dbConnection, req, m_id, artist->id() );
return sqlite::Tools::executeInsert( m_dbConnection, req, m_id, artist->id() );
}
bool Album::removeArtist(Artist* artist)
......
......@@ -108,7 +108,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::executeRequest( m_dbConnection, req, media->id(), artistForeignKey );
return sqlite::Tools::executeInsert( m_dbConnection, req, media->id(), artistForeignKey );
}
const std::string& Artist::artworkUrl() const
......@@ -190,7 +190,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(?),(?)";
return sqlite::Tools::executeRequest( dbConnection, req, medialibrary::UnknownArtistID,
return sqlite::Tools::executeInsert( dbConnection, req, medialibrary::UnknownArtistID,
medialibrary::VariousArtistID );
}
......
......@@ -334,7 +334,7 @@ bool Media::addLabel( LabelPtr label )
return false;
}
const char* req = "INSERT INTO LabelFileRelation VALUES(?, ?)";
return sqlite::Tools::executeRequest( m_dbConnection, req, label->id(), m_id );
return sqlite::Tools::executeInsert( m_dbConnection, req, label->id(), m_id );
}
bool Media::removeLabel( LabelPtr label )
......
......@@ -233,6 +233,13 @@ class Tools
return executeDelete( dbConnectionWeak, req, std::forward<Args>( args )... );
}
template <typename... Args>
static bool executeInsert( DBConnection dbConnectionWeak, const std::string& req, Args&&... args )
{
// The code would be exactly the same, do not freak out because it calls executeDelete :)
return executeDelete( dbConnectionWeak, req, std::forward<Args>( args )... );
}
/**
* Inserts a record to the DB and return the newly created primary key.
* Returns 0 (which is an invalid sqlite primary key) when insertion fails.
......
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