diff --git a/orm_lib/inc/drogon/orm/DbClient.h b/orm_lib/inc/drogon/orm/DbClient.h index e254668c..6646c956 100644 --- a/orm_lib/inc/drogon/orm/DbClient.h +++ b/orm_lib/inc/drogon/orm/DbClient.h @@ -300,12 +300,12 @@ inline void internal::TrasactionAwaiter::await_suspend( { assert(client_ != nullptr); client_->newTransactionAsync( - [this, handle](const std::shared_ptr transacton) { - if (transacton == nullptr) + [this, handle](const std::shared_ptr &transaction) { + if (transaction == nullptr) setException(std::make_exception_ptr( - std::runtime_error("Failed to create transaction"))); + Failure("Failed to create transaction"))); else - setValue(transacton); + setValue(transaction); handle.resume(); }); } diff --git a/orm_lib/tests/db_test.cc b/orm_lib/tests/db_test.cc index b57aa2a4..8ce12abb 100644 --- a/orm_lib/tests/db_test.cc +++ b/orm_lib/tests/db_test.cc @@ -33,7 +33,7 @@ using namespace drogon::orm; #define GREEN "\033[32m" /* Green */ #ifdef __cpp_impl_coroutine -constexpr int postgre_tests = 46; +constexpr int postgre_tests = 47; constexpr int mysql_tests = 47; constexpr int sqlite_tests = 49; #else @@ -743,9 +743,9 @@ void doPostgreTest(const drogon::orm::DbClientPtr &clientPtr) testOutput(result.size() != 0, "postgresql - DbClient coroutine interface(0)"); } - catch (const Failure &e) + catch (const DrogonDbException &e) { - std::cerr << e.what() << std::endl; + std::cerr << e.base().what() << std::endl; testOutput(false, "postgresql - DbClient coroutine interface(0)"); } /// 7.2 Parameter binding @@ -756,11 +756,26 @@ void doPostgreTest(const drogon::orm::DbClientPtr &clientPtr) testOutput(result.size() != 0, "postgresql - DbClient coroutine interface(1)"); } - catch (const Failure &e) + catch (const DrogonDbException &e) { - std::cerr << e.what() << std::endl; + std::cerr << e.base().what() << std::endl; testOutput(false, "postgresql - DbClient coroutine interface(1)"); } + /// 7.3 Transactions + try + { + auto trans = co_await clientPtr->newTransactionCoro(); + auto result = + co_await trans->execSqlCoro("select * from users where 1=$1;", + 1); + testOutput(result.size() != 0, + "postgresql - DbClient coroutine interface(2)"); + } + catch (const DrogonDbException &e) + { + std::cerr << e.base().what() << std::endl; + testOutput(false, "postgresql - DbClient coroutine interface(2)"); + } }; drogon::sync_wait(coro_test()); #endif @@ -1394,12 +1409,12 @@ void doMysqlTest(const drogon::orm::DbClientPtr &clientPtr) auto result = co_await clientPtr->execSqlCoro("select * from users;"); testOutput(result.size() != 0, - "postgresql - DbClient coroutine interface(0)"); + "mysql - DbClient coroutine interface(0)"); } - catch (const Failure &e) + catch (const DrogonDbException &e) { - std::cerr << e.what() << std::endl; - testOutput(false, "postgresql - DbClient coroutine interface(0)"); + std::cerr << e.base().what() << std::endl; + testOutput(false, "mysql - DbClient coroutine interface(0)"); } /// 7.2 Parameter binding try @@ -1407,12 +1422,12 @@ void doMysqlTest(const drogon::orm::DbClientPtr &clientPtr) auto result = co_await clientPtr->execSqlCoro( "select * from users where 1=?;", 1); testOutput(result.size() != 0, - "postgresql - DbClient coroutine interface(1)"); + "mysql - DbClient coroutine interface(1)"); } - catch (const Failure &e) + catch (const DrogonDbException &e) { - std::cerr << e.what() << std::endl; - testOutput(false, "postgresql - DbClient coroutine interface(1)"); + std::cerr << e.base().what() << std::endl; + testOutput(false, "mysql - DbClient coroutine interface(1)"); } }; drogon::sync_wait(coro_test()); @@ -2074,12 +2089,12 @@ void doSqliteTest(const drogon::orm::DbClientPtr &clientPtr) auto result = co_await clientPtr->execSqlCoro("select * from users;"); testOutput(result.size() != 0, - "postgresql - DbClient coroutine interface(0)"); + "sqlite3 - DbClient coroutine interface(0)"); } - catch (const Failure &e) + catch (const DrogonDbException &e) { - std::cerr << e.what() << std::endl; - testOutput(false, "postgresql - DbClient coroutine interface(0)"); + std::cerr << e.base().what() << std::endl; + testOutput(false, "sqlite3 - DbClient coroutine interface(0)"); } /// 7.2 Parameter binding try @@ -2087,12 +2102,12 @@ void doSqliteTest(const drogon::orm::DbClientPtr &clientPtr) auto result = co_await clientPtr->execSqlCoro( "select * from users where 1=?;", 1); testOutput(result.size() != 0, - "postgresql - DbClient coroutine interface(1)"); + "sqlite3 - DbClient coroutine interface(1)"); } - catch (const Failure &e) + catch (const DrogonDbException &e) { - std::cerr << e.what() << std::endl; - testOutput(false, "postgresql - DbClient coroutine interface(1)"); + std::cerr << e.base().what() << std::endl; + testOutput(false, "sqlite3 - DbClient coroutine interface(1)"); } }; drogon::sync_wait(coro_test()); diff --git a/trantor b/trantor index b7c16286..e35fd046 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit b7c16286cdd4147e6ddf6b3831dc0578c794c10b +Subproject commit e35fd046ac8a58bec3557c0c207a3e0b8ae57d38