Skip to content

Updating boolean data causes an error #74

@mcraveiro

Description

@mcraveiro

Hi sqlgen developers,

thanks very much for the fix for #69 - it works well for inserting new elements and reading them back out.

However, I have bumped into a slight problem when updating existing elements; I wonder if it is covered by this fix. Let login_info_entity be defined as follows:

struct login_info_entity {
    constexpr static const char* schema = "oresdb";
    constexpr static const char* tablename = "login_info";

    sqlgen::PrimaryKey<std::string> account_id;
    std::string last_ip;
    std::string last_attempt_ip;
    int failed_logins;
    bool locked;
    sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S"> last_login = "9999-12-31 23:59:59";
    bool online;
};

And the update like so:

    auto entity = login_info_mapper::map(login_info);
    const auto query = sqlgen::update<login_info_entity>(
        "last_ip"_c.set(entity.last_ip),
        "last_attempt_ip"_c.set(entity.last_attempt_ip),
        "failed_logins"_c.set(entity.failed_logins),
        "locked"_c.set(true),
        "last_login"_c.set(entity.last_login),
        "online"_c.set(entity.online)
    ) | where("account_id"_c == entity.account_id);

This triggers the following error:

2025-10-23 11:00:12.025959 [ERROR] [ores.accounts.repository.login_info_repository] Executing 'UPDATE "oresdb"."login_info" SET "last_ip" = '0.0.0.0', "last_attempt_ip" = '127.0.0.1', "failed_logins" = 1, "locked" = 1, "last_login" = '1969-12-31 23:00:00', "online" = 0 WHERE "account_id" = '019a0e58-a91a-7526-8706-20aa6c5f209c';' failed: ERROR:  column "locked" is of type boolean but expression is of type integer
LINE 1: ...p" = '127.0.0.1', "failed_logins" = 1, "locked" = 1, "last_l...
                                                             ^
HINT:  You will need to rewrite or cast the expression.

This seems to imply that, on the update path, we are somehow converting "true" to "1". I noticed that the tests seem to cover reading and writing, but not updating, e.g.:

Image

Perhaps an additional change is required for the update path?

Many thanks for your time.

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions