Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions orm_lib/inc/drogon/orm/DbTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ enum FieldType
MySqlNull,
MySqlString,
DrogonDefaultValue,
MySqlUTiny,
MySqlUShort,
MySqlULong,
MySqlULongLong,
Comment on lines +36 to +39
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unsigned integer enum values are added at the end of the enum, after MySqlString and DrogonDefaultValue. While this maintains backward compatibility with existing enum values, it creates a disorganized structure where related types (signed/unsigned pairs) are separated.

Consider whether the enum ordering could cause confusion or maintenance issues. If the enum values are persisted or used in serialization, the current approach is correct. Otherwise, consider documenting why unsigned types are placed at the end rather than grouped with their signed counterparts.

Copilot uses AI. Check for mistakes.
};

} // namespace internal
Expand Down
68 changes: 67 additions & 1 deletion orm_lib/inc/drogon/orm/SqlBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <string>
#include <vector>
#include <optional>
#include <type_traits>
#ifdef _WIN32
#include <winsock2.h>
#else // some Unix-like OS
Expand Down Expand Up @@ -414,7 +415,7 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable
objs_.push_back(obj);
parameters_.push_back((char *)obj.get());
lengths_.push_back(0);
formats_.push_back(getMysqlTypeBySize(sizeof(T)));
formats_.push_back(getMysqlType<ParaType>());
}
else if (type_ == ClientType::Sqlite3)
{
Expand Down Expand Up @@ -599,6 +600,71 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable

private:
static int getMysqlTypeBySize(size_t size);

template <typename T>
static int getMysqlType()
{
if constexpr (std::is_same_v<T, bool>)
{
return MySqlTiny;
}
else if constexpr (std::is_same_v<T, int8_t> ||
std::is_same_v<T, signed char>)
{
return MySqlTiny;
}
else if constexpr (std::is_same_v<T, uint8_t> ||
std::is_same_v<T, unsigned char>)
{
return MySqlUTiny;
}
else if constexpr (std::is_same_v<T, int16_t> ||
std::is_same_v<T, short>)
{
return MySqlShort;
}
else if constexpr (std::is_same_v<T, uint16_t> ||
std::is_same_v<T, unsigned short>)
{
return MySqlUShort;
}
else if constexpr (std::is_same_v<T, int32_t> ||
(std::is_same_v<T, int> && sizeof(int) == 4) ||
(std::is_same_v<T, long> && sizeof(long) == 4))
{
return MySqlLong;
}
else if constexpr (std::is_same_v<T, uint32_t> ||
(std::is_same_v<T, unsigned int> &&
sizeof(unsigned int) == 4) ||
(std::is_same_v<T, unsigned long> &&
sizeof(unsigned long) == 4))
{
return MySqlULong;
}
else if constexpr (std::is_same_v<T, int64_t> ||
std::is_same_v<T, long long> ||
(std::is_same_v<T, long> && sizeof(long) == 8))
{
return MySqlLongLong;
}
else if constexpr (std::is_same_v<T, uint64_t> ||
std::is_same_v<T, unsigned long long> ||
(std::is_same_v<T, unsigned long> &&
sizeof(unsigned long) == 8))
{
return MySqlULongLong;
}
else if constexpr (std::is_same_v<T, char>)
{
return MySqlTiny;
Comment thread
an-tao marked this conversation as resolved.
Outdated
}
else
{
static_assert(sizeof(T) == 0, "Unsupported type for MySQL binding");
}
}

std::shared_ptr<std::string> sqlPtr_;
const char *sqlViewPtr_;
size_t sqlViewLength_;
Expand Down
16 changes: 16 additions & 0 deletions orm_lib/src/mysql_impl/MysqlConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,22 @@ void MysqlConnection::execSqlInLoop(
sql_.append(
std::to_string(*((int64_t *)parameters[i])));
break;
case internal::MySqlUTiny:
sql_.append(
std::to_string(*((unsigned char *)parameters[i])));
break;
case internal::MySqlUShort:
sql_.append(
std::to_string(*((unsigned short *)parameters[i])));
break;
case internal::MySqlULong:
sql_.append(
std::to_string(*((uint32_t *)parameters[i])));
break;
case internal::MySqlULongLong:
sql_.append(
std::to_string(*((uint64_t *)parameters[i])));
break;
case internal::MySqlNull:
sql_.append("NULL");
break;
Expand Down
Loading