Refactor ID retrieval logic in Database class
Simplify the return logic for getAlbumId, getArtistId, and getGenreId functions by returning results directly when available or after assignment.
This commit is contained in:
Binary file not shown.
+4
-2
@@ -252,7 +252,7 @@ std::optional<int> db::getAlbumId( const std::string& albumTitle ) {
|
|||||||
if (sqlite3_step( stmt ) == SQLITE_ROW ) {
|
if (sqlite3_step( stmt ) == SQLITE_ROW ) {
|
||||||
id = sqlite3_column_int( stmt, 0 );
|
id = sqlite3_column_int( stmt, 0 );
|
||||||
}
|
}
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int> db::getArtistId( const std::string& artistName ) {
|
std::optional<int> db::getArtistId( const std::string& artistName ) {
|
||||||
@@ -264,8 +264,9 @@ std::optional<int> db::getArtistId( const std::string& artistName ) {
|
|||||||
|
|
||||||
std::optional<int> id;
|
std::optional<int> id;
|
||||||
if (sqlite3_step( stmt ) == SQLITE_ROW ) {
|
if (sqlite3_step( stmt ) == SQLITE_ROW ) {
|
||||||
id = sqlite3_column_int( stmt, 0 );
|
return sqlite3_column_int( stmt, 0 );
|
||||||
}
|
}
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int> db::getGenreId( const std::string& genre ) {
|
std::optional<int> db::getGenreId( const std::string& genre ) {
|
||||||
@@ -279,4 +280,5 @@ std::optional<int> db::getGenreId( const std::string& genre ) {
|
|||||||
if (sqlite3_step( stmt ) == SQLITE_ROW ) {
|
if (sqlite3_step( stmt ) == SQLITE_ROW ) {
|
||||||
id = sqlite3_column_int( stmt, 0 );
|
id = sqlite3_column_int( stmt, 0 );
|
||||||
}
|
}
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "../include/Database.h"
|
#include "../include/Database.h"
|
||||||
#include "../include/Containers.h"
|
#include "../include/Containers.h"
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
using db = Database;
|
using db = Database;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user