Skip to content

Commit

Permalink
TgBot++: database: sqlite: Remove unnessary try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Royna2544 committed Jun 28, 2024
1 parent 78cc4dd commit 1234604
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions src/database/SQLiteDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,15 @@ SQLiteDatabase::ListResult SQLiteDatabase::addUserToList(InfoType type,
case ListResult::BACKEND_ERROR:
return res;
}

try {
auto helper = Helper::create(db, Helper::kInsertUserFile);
if (!helper->prepare()) {
return ListResult::BACKEND_ERROR;
}
helper->addArgument(user)
->addArgument(static_cast<int>(type))
->bindArguments();
if (helper->execute()) {
return ListResult::OK;
}
} catch (const std::runtime_error& e) {
LOG(ERROR) << "Error inserting user: " << e.what();
auto helper = Helper::create(db, Helper::kInsertUserFile);
if (!helper->prepare()) {
return ListResult::BACKEND_ERROR;
}
helper->addArgument(user)
->addArgument(static_cast<int>(type))
->bindArguments();
if (helper->execute()) {
return ListResult::OK;
}
return ListResult::BACKEND_ERROR;
}
Expand Down Expand Up @@ -291,19 +286,15 @@ SQLiteDatabase::ListResult SQLiteDatabase::removeUserFromList(
return res;
}

try {
auto helper = Helper::create(db, Helper::kRemoveUserFile.data());
if (!helper->prepare()) {
return ListResult::BACKEND_ERROR;
}
helper->addArgument(user);
helper->addArgument(static_cast<int>(toInfoType(type)));
helper->bindArguments();
if (helper->execute()) {
return ListResult::OK;
}
} catch (const std::runtime_error& e) {
LOG(ERROR) << "Error removing user: " << e.what();
auto helper = Helper::create(db, Helper::kRemoveUserFile.data());
if (!helper->prepare()) {
return ListResult::BACKEND_ERROR;
}
helper->addArgument(user);
helper->addArgument(static_cast<int>(toInfoType(type)));
helper->bindArguments();
if (helper->execute()) {
return ListResult::OK;
}
return ListResult::BACKEND_ERROR;
}
Expand All @@ -325,17 +316,12 @@ void SQLiteDatabase::initDatabase() {
ListResult result = ListResult::BACKEND_ERROR;
std::optional<Helper::Row> row;

try {
auto helper = Helper::create(db, Helper::kFindUserFile.data());
if (!helper->prepare()) {
return result;
}
helper->addArgument(user);
row = helper->execAndGetRow();
} catch (const std::runtime_error& e) {
LOG(ERROR) << "Error checking for user: " << e.what();
auto helper = Helper::create(db, Helper::kFindUserFile.data());
if (!helper->prepare()) {
return result;
}
helper->addArgument(user);
row = helper->execAndGetRow();
if (row) {
const auto info = static_cast<InfoType>(row->get<int>(0));
const auto reqinfo = type;
Expand Down

0 comments on commit 1234604

Please sign in to comment.