Fix an error when binding a function pointer to SqlBinder (#1097)
This commit is contained in:
parent
f522d2d70e
commit
d6b09c9e1b
|
@ -176,8 +176,8 @@ class CallbackHolder : public CallbackHolderBase
|
|||
run(result);
|
||||
}
|
||||
|
||||
CallbackHolder(Function &&function)
|
||||
: function_(std::forward<Function>(function))
|
||||
template <typename T>
|
||||
CallbackHolder(T &&function) : function_(std::forward<T>(function))
|
||||
{
|
||||
static_assert(traits::isSqlCallback,
|
||||
"Your sql callback function type is wrong!");
|
||||
|
@ -323,7 +323,8 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable
|
|||
SqlBinder &operator=(SqlBinder &&that) = delete;
|
||||
~SqlBinder();
|
||||
template <typename CallbackType,
|
||||
typename traits = FunctionTraits<CallbackType>>
|
||||
typename traits =
|
||||
FunctionTraits<typename std::decay<CallbackType>::type>>
|
||||
typename std::enable_if<traits::isExceptCallback && traits::isPtr,
|
||||
self>::type &
|
||||
operator>>(CallbackType &&callback)
|
||||
|
@ -335,7 +336,8 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable
|
|||
}
|
||||
|
||||
template <typename CallbackType,
|
||||
typename traits = FunctionTraits<CallbackType>>
|
||||
typename traits =
|
||||
FunctionTraits<typename std::decay<CallbackType>::type>>
|
||||
typename std::enable_if<traits::isExceptCallback && !traits::isPtr,
|
||||
self>::type &
|
||||
operator>>(CallbackType &&callback)
|
||||
|
@ -346,12 +348,13 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable
|
|||
}
|
||||
|
||||
template <typename CallbackType,
|
||||
typename traits = FunctionTraits<CallbackType>>
|
||||
typename traits =
|
||||
FunctionTraits<typename std::decay<CallbackType>::type>>
|
||||
typename std::enable_if<traits::isSqlCallback, self>::type &operator>>(
|
||||
CallbackType &&callback)
|
||||
{
|
||||
callbackHolder_ = std::shared_ptr<CallbackHolderBase>(
|
||||
new CallbackHolder<CallbackType>(
|
||||
new CallbackHolder<typename std::decay<CallbackType>::type>(
|
||||
std::forward<CallbackType>(callback)));
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
using namespace std::chrono_literals;
|
||||
using namespace drogon::orm;
|
||||
|
||||
void expFunction(const DrogonDbException &e)
|
||||
{
|
||||
}
|
||||
#if USE_POSTGRESQL
|
||||
DbClientPtr postgreClient;
|
||||
DROGON_TEST(PostgreTest)
|
||||
|
@ -40,6 +43,12 @@ DROGON_TEST(PostgreTest)
|
|||
// Prepare the test environment
|
||||
*clientPtr << "DROP TABLE IF EXISTS USERS" >> [TEST_CTX](const Result &r) {
|
||||
SUCCESS();
|
||||
clientPtr->execSqlAsync(
|
||||
"select 1 as result",
|
||||
[TEST_CTX](const drogon::orm::Result &r) {
|
||||
MANDATE(r.size() == 1);
|
||||
},
|
||||
expFunction);
|
||||
} >> [TEST_CTX](const DrogonDbException &e) {
|
||||
FAULT("postgresql - Prepare the test environment(0) what():" +
|
||||
std::string(e.base().what()));
|
||||
|
@ -674,6 +683,7 @@ DROGON_TEST(PostgreTest)
|
|||
}
|
||||
};
|
||||
drogon::sync_wait(coro_test());
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@ -686,7 +696,15 @@ DROGON_TEST(MySQLTest)
|
|||
REQUIRE(clientPtr != nullptr);
|
||||
// Prepare the test environment
|
||||
*clientPtr << "CREATE DATABASE IF NOT EXISTS drogonTestMysql" >>
|
||||
[TEST_CTX](const Result &r) { SUCCESS(); } >>
|
||||
[TEST_CTX](const Result &r) {
|
||||
SUCCESS();
|
||||
clientPtr->execSqlAsync(
|
||||
"select 1 as result",
|
||||
[TEST_CTX](const drogon::orm::Result &r) {
|
||||
MANDATE(r.size() == 1);
|
||||
},
|
||||
expFunction);
|
||||
} >>
|
||||
[TEST_CTX](const DrogonDbException &e) {
|
||||
FAULT("mysql - Prepare the test environment(0) what():" +
|
||||
std::string(e.base().what()));
|
||||
|
@ -1260,6 +1278,7 @@ DROGON_TEST(MySQLTest)
|
|||
}
|
||||
};
|
||||
drogon::sync_wait(coro_test());
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
@ -1274,6 +1293,12 @@ DROGON_TEST(SQLite3Test)
|
|||
// Prepare the test environment
|
||||
*clientPtr << "DROP TABLE IF EXISTS users" >> [TEST_CTX](const Result &r) {
|
||||
SUCCESS();
|
||||
clientPtr->execSqlAsync(
|
||||
"select 1 as result",
|
||||
[TEST_CTX](const drogon::orm::Result &r) {
|
||||
MANDATE(r.size() == 1);
|
||||
},
|
||||
expFunction);
|
||||
} >> [TEST_CTX](const DrogonDbException &e) {
|
||||
FAULT("sqlite3 - Prepare the test environment(0): what():" +
|
||||
std::string(e.base().what()));
|
||||
|
@ -1906,6 +1931,7 @@ DROGON_TEST(SQLite3Test)
|
|||
trantor::EventLoop::getEventLoopOfCurrentThread(), 1.0s);
|
||||
};
|
||||
drogon::sync_wait(coro_test());
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue