I need to loop through a sqlite db but the function i'm using doesn't work at all, this is the code i'm using:
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"CarrelloMese.sqlite"]];
NSUInteger helper;
helper = 0;
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &Carrello) == SQLITE_OK) {
NSString *checkSQL = [NSString stringWithFormat: @"SELECT FROM CarrelloMese"];
const char *insert_stmt = [checkSQL UTF8String];
if(sqlite3_prepare_v2(Carrello, insert_stmt, -1, &statement, NULL)) {
while(sqlite3_step(statement) == SQLITE_ROW) {
[indexProdotti insertObject:[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)] atIndex:helper];
}
}
sqlite3_finalize(statement);
sqlite3_close(Carrello);
}
When it reaches the While
it doesn't enter, but I can't understand what's the problem.. The values are stored correctly on the DB (I checked with SqliteManager) and If I use a Count function within the app the count is correct, is there a problem with the code?
Your code seems to be correct. You forgot to add * in query.
Try this: