Skip to content

Conversation

@khalilluo
Copy link
Contributor

Fix uint32_t values > INT32_MAX being converted to negative numbers.

  • Add MySqlUTiny/UShort/ULong/ULongLong enum types
  • Replace getMysqlTypeBySize() with getMysqlType() template
  • Update MysqlConnection to handle unsigned type casting
  • Maintain backward compatibility

Fix uint32_t values > INT32_MAX being converted to negative numbers.

- Add MySqlUTiny/UShort/ULong/ULongLong enum types
- Replace getMysqlTypeBySize() with getMysqlType<T>() template
- Update MysqlConnection to handle unsigned type casting
- Maintain backward compatibility
Fix compilation error where getMysqlType<bool> was not handled,
causing static_assert failures when Json::Value::asBool() is used.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for unsigned integer types in the MySQL ORM to fix an issue where uint32_t values greater than INT32_MAX were being incorrectly converted to negative numbers. The implementation introduces new enum types for unsigned integers and replaces the size-based type detection with a more precise template-based approach.

Key Changes:

  • Added four new MySQL field type enums (MySqlUTiny, MySqlUShort, MySqlULong, MySqlULongLong) for unsigned integers
  • Replaced getMysqlTypeBySize() with template function getMysqlType<T>() that uses type traits to distinguish between signed and unsigned types
  • Updated MysqlConnection to handle the new unsigned type cases with appropriate casting

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
orm_lib/inc/drogon/orm/DbTypes.h Adds four new enum values for unsigned integer types (UTiny, UShort, ULong, ULongLong)
orm_lib/inc/drogon/orm/SqlBinder.h Introduces template function getMysqlType<T>() using type traits to precisely determine MySQL types, including unsigned variants
orm_lib/src/mysql_impl/MysqlConnection.cc Adds case handlers for unsigned integer types with proper casting to uint8_t, uint16_t, uint32_t, and uint64_t

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +39
MySqlUTiny,
MySqlUShort,
MySqlULong,
MySqlULongLong,
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.
@an-tao an-tao merged commit 3ce6a77 into drogonframework:master Dec 25, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants