문제

I'm having a problem with inserting an int to an SQLite database for my iOS app. When I select it, it's always zero.

I'm creating this table:

CREATE TABLE followedCategory(id TEXT(256) primary key, title TEXT(256), img BLOB, following INTEGER)

The last param (following) is causing the problems. I insert records with this piece of code:

DatabaseRecord *rec = [database query:@"INSERT INTO followedCategory VALUES (?1, ?2, ?3, ?4)" params:category.categoryId, category.title, UIImagePNGRepresentation(category.image), [NSNumber numberWithInt:1], nil];
[rec next];

When I query the table with this:

DatabaseRecord *rec = [database query:@"SELECT COUNT(*) FROM followedCategory WHERE following = ?1" params:[NSNumber numberWithInt:1], nil];
[rec next];

return [rec intAtCol:0];

I always get zero results back. When I run this:

DatabaseRecord *recTest = [database query:@"SELECT following FROM followedCategory LIMIT 2"];
[recTest next];
NSLog(@"First following is %i", [recTest intAtCol:0]);
[recTest next];
NSLog(@"Second following is %i", [recTest intAtCol:1]);

I get back this in the logs:

2014-01-29 10:24:58.595 App[1940:60b] First following is 0
2014-01-29 10:24:58.596 App[1940:60b] Second following is 0

I guess the insert query is causing the problems as , but I can't figure out why. By the way, I'm using an NSNumber because the Database class converts it to an int, can't pass an int to the DatabaseRecord.

Anyone a suggestion? Thanks in advance!

도움이 되었습니까?

해결책

I think that Inserting of BLOB may cause that error. Just refere this below link may help you lot. sqlite3 insert and read BLOB data in database

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top