I dont know the exact problem but have been scratching my head for almost 4 hrs now.
if (sqlite3_open([dataBasePath UTF8String], &bookDB) == SQLITE_OK) {
NSString *Query = [NSString stringWithFormat:@"SELECT * FROM linktable WHERE pageid = 2"];
if (sqlite3_prepare_v2(bookDB, [Query UTF8String], -1, &statement1, nil) == SQLITE_OK) {
markupsArray = [NSMutableArray arrayWithCapacity:1];
NSLog(@"sqlite3_step(statement1) is %d",sqlite3_step(statement1));
while (sqlite3_step(statement1) == SQLITE_ROW) {
NSLog(@"yup");
MarkupData *markUpObject = [[MarkupData alloc] init];
markUpObject.linkID = [[[NSString alloc] initWithUTF8String:(const char*) sqlite3_column_text(statement1, 0)] autorelease];
markUpObject.pageID = [[[NSString alloc] initWithUTF8String:(const char*) sqlite3_column_text(statement1, 1)] autorelease];
markUpObject.markupID = [[[NSString alloc] initWithUTF8String:(const char*) sqlite3_column_text(statement1, 2)] autorelease];
markUpObject.folioNumber = [[[NSString alloc] initWithUTF8String:(const char*) sqlite3_column_text(statement1, 5)] autorelease];
[markupsArray addObject:markUpObject];
}
}
}
Here comes the strange thing. The value of sqlite3_step(statement1) is 100, so is the value of SQLITE_ROW. But even then the while loop is not getting executed. Can any one help me crack this strange scenario please… Just got struck up here.. 🙁
If your sqlite query is returning just 1 record, the
sqlite3_step()actually steps through the record. Since you have yourNSLogstatement executingsqlite3_step(), the record is already stepped through here. Hence, yourwhileloop won’t execute as there are no more rows to step through.