Reputation: 537
I'm starting to develop a small iOS application just for learning, and I'm attempting to use SQLite to store my app data. I'm using a simple CRUD operations, but when I compile the app (I want to try it in the device emulator) i've got this error
I've added libsqlite3.dylib to my project dependences.
I've tried many solutions, bun no one fix my problem. Any idea about what i'm doing wrong?
Thank you so much
ps. The code are the following:
-(int) getPushCount {
int count = 0;
const char *dbpath = [databasePath UTF8String];
if(sqlite3_open(dbpath, &database) == SQLITE_OK) {
NSString *query = [NSString stringWithFormat:@"SELECT COUNT(*) FROM recived_push WHERE read = 1"];
const char *getQuery = [query UTF8String];
if(sqlite3_prepare_v2(database, getQuery, -1, &statement, NULL) == SQLITE_OK) {
while(sqlite_step(statement) == SQLITE_ROW) {
count = sqlite_column_int(statement,0);
}
} else {
NSLog(@"Failed from sqlite3_prepare_v2.");
NSLog(@"Error is: %s", sqlite3_errmsg(database));
}
sqlite3_finalize(statement);
sqlite3_close(database);
} else {
NSLog(@"Oops! Something went terribly wrong...");
NSLog(@"%s",sqlite3_errmsg(database));
return nil;
}
NSLog(@"**Count: %d",count);
return count;
}
Upvotes: 1
Views: 453
Reputation: 3888
change your code like this..
while (sqlite3_step(statement)== SQLITE_ROW) {
count = sqlite3_column_int(statement, 0);
}
Upvotes: 2