views:

27

answers:

1

Hi!

I am working on an iPhone project where we need to fetch data from aa sqlite database. I have done this many times before, and everything works out fine. But now I am having problems fetching the value of an integer field (the primary key).

The varchar fields I can fetch with:

NSString *forfatter=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectstmt, 11)];

I suppose i have to use sqlite3_column_int for this, but i cant find out how to get the number right. When i NSLog it, it always comes out wrong, like: "107096896" instead of "35".

Here is one of the ways i tried to do it:

int pKey = sqlite3_column_int(selectstmt, 0);
NSLog(@"fant id: %i",pKey);

I also tried with NSIntegers and NSUIntegers. Can anyone help me out with this one? I would be very grateful!

A: 

As Donald points out above, something was wrong with the stored data. It traces back to my insert statements where i used this code to insert the int:

int newID=8;
sqlite3_bind_int(insertStmt,  1, newID);

If i use NSInteger instead, it works out:

NSInteger newID=8;
sqlite3_bind_int(insertStmt,  1, newID);
Ezop
Frankly, that would worry me. sqlite3_bind_int() is documented to take an int as its third parameter, so there is something weird going on.
JeremyP