tags:

views:

206

answers:

2

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:

http://www.sqlite.org/c3ref/int64.html

AlbertoPL
sizeof(long long *) is probably going to be 4 on a 32-bit system. ITYM sizeof(long long).
Sinan Ünür
Good call, thank you Sinan.
AlbertoPL
+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