sqlite c++ and unsigned int key

sqlite c++ and unsigned int key

本文关键字:int key unsigned and c++ sqlite      更新时间:2023-10-16

我正在尝试迁移到SQLite。在我的C++程序中,我使用unsigned int key来存储id。当我将数据从C++程序序列化到SQLite,然后将其反序列化或浏览数据库时,我会在列中看到负值(带符号)。

我在序列化时使用以下函数绑定unsigned ints

sqlite3_bind_int(stmt, 1, key);

键的表列在创建时声明为INT。也许这是我的错误?

有什么建议可以正确地将unsigned ints序列化到SQLite中并在没有更改的情况下加载回来?

SQLite的类型系统不支持无符号整数。但是您可以使用sqlite3_bind_int64unsigned int(假设它是32位的)可以无损地转换为int64_t