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!