Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion orm_lib/inc/drogon/orm/CoroMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,16 @@ class CoroMapper : public Mapper<T>
this->clear();
static_assert(!std::is_same_v<typename T::PrimaryKeyType, void>,
"No primary key in the table!");
std::vector<std::string> colNames = obj.updateColumns();
if (colNames.empty())
{
callback(0);
return;
}
std::string sql = "update ";
sql += T::tableName;
sql += " set ";
for (auto const &colName : obj.updateColumns())
for (auto const &colName : colNames)
{
sql += colName;
sql += " = $?,";
Expand Down
26 changes: 23 additions & 3 deletions orm_lib/inc/drogon/orm/Mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,15 @@ inline size_t Mapper<T>::update(const T &obj) noexcept(false)
clear();
static_assert(!std::is_same_v<typename T::PrimaryKeyType, void>,
"No primary key in the table!");
std::vector<std::string> colNames = obj.updateColumns();
if (colNames.empty())
{
return 0;
}
std::string sql = "update ";
sql += T::tableName;
sql += " set ";
for (auto const &colName : obj.updateColumns())
for (auto const &colName : colNames)
{
sql += colName;
sql += " = $?,";
Expand Down Expand Up @@ -1415,10 +1420,17 @@ inline void Mapper<T>::update(const T &obj,
clear();
static_assert(!std::is_same_v<typename T::PrimaryKeyType, void>,
"No primary key in the table!");

std::vector<std::string> colNames = obj.updateColumns();
if (colNames.empty())
{
rcb(0);
return;
}
std::string sql = "update ";
sql += T::tableName;
sql += " set ";
for (auto const &colName : obj.updateColumns())
for (auto const &colName : colNames)
{
sql += colName;
sql += " = $?,";
Expand Down Expand Up @@ -1478,10 +1490,18 @@ inline std::future<size_t> Mapper<T>::updateFuture(const T &obj) noexcept
clear();
static_assert(!std::is_same_v<typename T::PrimaryKeyType, void>,
"No primary key in the table!");
std::vector<std::string> colNames = obj.updateColumns();
if (colNames.empty())
{
std::shared_ptr<std::promise<size_t>> prom =
std::make_shared<std::promise<size_t>>();
prom->set_value(0);
return prom->get_future();
}
std::string sql = "update ";
sql += T::tableName;
sql += " set ";
for (auto const &colName : obj.updateColumns())
for (auto const &colName : colNames)
{
sql += colName;
sql += " = $?,";
Expand Down
Loading