I have to return differing types from my perform, which is liable for executing SQL queries.
I suppose template perform is what I would like, however I am having some issues figuring the implementation out.
What I wish to do, is return false/true when question accommodates “INSERT”, and in case which question accommodates “SELECT” to return nullptr/unique_ptr following this logic (beneath strategies include solely crucial code):
bool executeInsert(const char* question) {
std::unique_ptr<MYSQL> connection = establishConnection();
MYSQL* connectionRaw = connection.get();
if (connectionRaw) {
int queryState;
queryState = mysql_query(connectionRaw, question);
if (queryState != 0) {
return false;
}
else {
return true;
}
}
else {
return false;
}
};
std::unique_ptr<MYSQL_RES> execute(const char* question) {
std::unique_ptr<MYSQL> connection = establishConnection();
MYSQL* connectionRaw = connection.get();
if (connectionRaw) {
int queryState;
queryState = mysql_query(connectionRaw, question);
if (queryState != 0) {
return nullptr;
}
else {
return std::make_unique<MYSQL_RES>(*mysql_store_result(connectionRaw));
}
}
else {
return nullptr;
}
}
I’m having bother with implementation of the template perform after checking for the key phrase insert/choose. What ought to it seem like and the way would I name it from outdoors the category?