SQLITE_INTEGER value bytes
sqlite
Solution
When SQLite steps into a record, all integer values are expanded to 64 bits. `sqlite3_column_int()` returns the lower 32 bits of that value without checking for overflows.
When you call `sqlite3_column_bytes()`, SQLite will convert the value to text, and return the number of characters.
You cannot know how large an integer value is before reading it. Afterwards, you can check the list in the record format documentation for the smallest possible format for that value, but if you want to be sure that integer values are never truncated to 32 bits, you have to always use `sqlite3_column_int64()`, or ensure that large values get never written to the DB in the first place (if that is possible).
Problem
I have a question about the data types in sqlite3. As a value of `SQLITE_INTEGER` can be stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value, if I only know that a column in SQlite database stores `SQLITE_INTEGER`, how can I know a value in this column is 4 bytes or 6-8 bytes integer, or which one should be used to get the value, `sqlite3_column_int()` or `sqlite3_column_int64()`? Can I use `sqlite3_column_bytes()` in this case? but according to the documentation, `sqlite3_column_bytes()` is primarily used for TEXT or BLOB. Thanks!