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

sqlite: Merge insert & executeInsert

parent 58862629
......@@ -227,7 +227,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::executeInsert( m_dbConnection, req, m_id, artist->id() );
return sqlite::Tools::insert( m_dbConnection, req, m_id, artist->id() ) != 0;
}
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::executeInsert( m_dbConnection, req, media->id(), artistForeignKey );
return sqlite::Tools::insert( m_dbConnection, req, media->id(), artistForeignKey ) != 0;
}
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(?),(?)";
sqlite::Tools::executeInsert( dbConnection, req, medialibrary::UnknownArtistID,
sqlite::Tools::insert( 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.
......
......@@ -334,7 +334,7 @@ bool Media::addLabel( LabelPtr label )
return false;
}
const char* req = "INSERT INTO LabelFileRelation VALUES(?, ?)";
return sqlite::Tools::executeInsert( m_dbConnection, req, label->id(), m_id );
return sqlite::Tools::insert( m_dbConnection, req, label->id(), m_id ) != 0;
}
bool Media::removeLabel( LabelPtr label )
......
......@@ -240,13 +240,6 @@ 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