Hello again.

In short, i get an error calling the same synchronized singleton DatabaseManager from different threads.

Here is what I am actually doing. As I was writing earlier, i am writing a dictionary application that is supposed to show translations for words from the database. In the main window, there is a tableview and a textfield. As a user types a word, i create a new NSOperation that calls the [DatabaseManager sharedManager] and calls the methods to select all the words beginning with the letters the user has typed. And then the tableview is filled with the words so selected.

That works ok until the user presses return to see the translation of the word he has typed. That action also calls the [DatabaseManager sharedManager] and calls the methods for selecting the whole article from the db. This results in the "library routine called out of sequence" error in sqlite. Selecting an article from the db worked perfectly well when it was not called after the procedure described above.

And when, after receiving an empty dictionary article, the user begins typing a new word in the search textfield, nothing happens with the tableview, and sqlite3_step function calls end with the "library routine called out of sequence" error.

Here are the relevant excerpts from the classes involved.

Database:

- (NSArray *) selectWordsBeginningWith:(NSString *) s {
        NSString *searchString = [NSString stringWithFormat:@"%...@%@", s, 
@"%%"];
NSMutableArray *mutableRet = [self itemsFromTable:@"english" usingStatement:readEnglish andSearchString:searchString]; NSMutableArray *arr2 = [self itemsFromTable:@"russian" usingStatement:readRussian andSearchString:searchString];

        [mutableRet addObjectsFromArray: arr2];
        
        sqlite3_reset(readEnglish);
        sqlite3_reset(readRussian);
        NSArray *ret = [[mutableRet copy] autorelease];

        return ret;
}


- (NSDictionary *) selectArticleWithId: (WordIdAndDatabase *) articleId {
        sqlite3_stmt *currentOne;
        
        if ([articleId.datbaseName isEqualToString:@"english"]) {
                currentOne = selectArticleEnglishToRussian;
        } else {
                currentOne = selectArticleRussianToEnglish;
        }
        
        NSString *originalWord = articleId.word;
        sqlite3_bind_int(currentOne, 1, articleId.wordId);
        NSMutableArray *translations = [[NSMutableArray alloc] init];
        
        while (sqlite3_step(currentOne) == SQLITE_ROW) {
[translations addObject:[NSString stringWithUTF8String:(char *) sqlite3_column_text(currentOne, 0)]];
        }
        
NSLog(@"There may be an error in the db things: %s", sqlite3_errmsg(database));

NSDictionary *ret = [NSDictionary dictionaryWithObjectsAndKeys:originalWord, @"original", translations, @"translations", nil];
        [translations release];
        
        sqlite3_reset(currentOne);
        return ret;
}

- (NSMutableArray *) itemsFromTable:(NSString *)table usingStatement: (sqlite3_stmt *)statement andSearchString:(NSString *) searchString {

NSMutableArray *mutableRet = [[[NSMutableArray alloc] init] autorelease]; sqlite3_bind_text(statement, 1, [searchString cStringUsingEncoding:NSUTF8StringEncoding], -1, SQLITE_TRANSIENT);
        while (sqlite3_step(statement) == SQLITE_ROW) {
NSString *s = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 0)];
                int wid = sqlite3_column_int(statement, 1);
[mutableRet addObject:[WordIdAndDatabase makeWithId:wid word:s andDatabaseName:table]];
        }
        
NSLog(@"There MIGHT BE an error in getting things from the db: %s", sqlite3_errmsg(database));
        return mutableRet;
}

Thank you for your attention.

Timofey.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to