开发者

Problem getting an integer from SQLite

开发者 https://www.devze.com 2023-01-15 01:24 出处:网络
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 开发者_JS百科everything works out fine. But now I am having problems fetc

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 开发者_JS百科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!


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消