I am preparing my app to be iOS 4 compatible and got the issue, that for some weird reason, enabling the 0 index of my segmentedControl causes the code to call the openDatabase method and closeDatabase method. I have been debugging the entire code, and figured out, that as soon as the segmentedControl is enabled, those two methods are called.
Here the excerpt of the log:
> 2012-04-17 17:20:59.294 Abiliator[27897:11003] viewWillAppear - before database open
2012-04-17 17:20:59.296 Abiliator[27897:11003] OpenDatabase
2012-04-17 17:20:59.297 Abiliator[27897:11003] viewWillAppear - loadAppSettings
2012-04-17 17:20:59.311 Abiliator[27897:11003] viewWillAppear - getCurrentLearningSubject
2012-04-17 17:20:59.340 Abiliator[27897:11003] viewWillAppear - switchLearningBoxControl
2012-04-17 17:20:59.341 Abiliator[27897:11003] Inside switchLearningBoxControl
**2012-04-17 17:20:59.394 Abiliator[27897:11003] OpenDatabase
2012-04-17 17:21:00.566 Abiliator[27897:11003] CloseDatabase**
2012-04-17 17:21:00.567 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.568 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.569 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.570 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.570 Abiliator[27897:11003] Finished switchLearningBoxControl
2012-04-17 17:21:00.571 Abiliator[27897:11003] viewWillAppear - getQuestionFromDB
2012-04-17 17:21:00.572 Abiliator[27897:11003] CloseDatabase
2012-04-17 17:21:00.572 Abiliator[27897:11003] Failed to close the database with message 'library routine called out of sequence'.
You see two subsequent open and close database method calls. However those are not explicitly called by my code, but some “ghost” process is executing that part of the code.
The very same code runs on iOS 5 just fine, no issues at all, neither in Simulator nor on the device.
Any idea, what the issue might be? Thanks.
- (void) switchLearningBoxControl:(NSString *) mySubjectID {
const char *sql = "select count (*) from ABILIATOR_CARD where learningbox = ? and subject_id = ?";
for (NSInteger mySegment=0;mySegment < 5;mySegment++) {
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
sqlite3_bind_int(selectstmt, 1, mySegment+1);
sqlite3_bind_text(selectstmt, 2, [mySubjectID UTF8String], -1, SQLITE_TRANSIENT);
if (sqlite3_step(selectstmt) == SQLITE_ROW) {
int count = sqlite3_column_int(selectstmt, 0);
if (count < 1) {
[self.learningBoxControl setEnabled:NO forSegmentAtIndex:mySegment];
}
else {
[self.learningBoxControl setEnabled:YES forSegmentAtIndex:mySegment];
}
}
else {
[self.learningBoxControl setEnabled:NO forSegmentAtIndex:mySegment];
}
}
else {
NSLog(@"Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement '%s'.", sqlite3_errmsg(database));
}
sqlite3_finalize(selectstmt);
}
}
in iOS 4 setEnabled calls the IBAction, iOS 5 does not. I have another open in that IBAction, which of course confuses the app 🙂 Was not aware of that change, as I have read the doc and did no see any such change between 4 and 5.