I'm reading data from a sqlite3 database using the C api. sqlite3_column_int64 returns a sqlite3_int64 object. How do I convert this to a long?
A:
A long in C is typically 32 bits, whereas you're looking at a 64 bit integer from sqlite. As long as you are using C, you can use the long long type.
Here is something you can reference for that:
http://home.att.net/~jackklein/c/inttypes.html#long_long
I would try dereferencing the sqlite3_int64 as a long long int and see if it works by doing a sizeof(long long)
EDIT: I found the typedefs for the sqlite_int64 that you can look at also as a reference:
AlbertoPL
2009-06-18 18:16:53
sizeof(long long *) is probably going to be 4 on a 32-bit system. ITYM sizeof(long long).
Sinan Ünür
2009-06-18 18:24:50
Good call, thank you Sinan.
AlbertoPL
2009-06-18 18:36:49
+1
A:
You should be using the standard integer types defined in stdint.h. You can then use int64_t and know that on every platform it will be 64 bits wide.
You can then just cast sqlite3_int64 to int64_t and you're good to go.
Nathan
2009-07-07 14:39:47