It looks like you're new here. If you want to get involved, click one of these buttons!
- (void)handleSearchForTerm:(NSString *)searchTerm
{
[self setSavedSearchTerm:searchTerm];
if ([self searchResults] == nil)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults:array];
[array release], array = nil;
}
[[self searchResults] removeAllObjects];
//test begin
if ([self searchResults_2] == nil)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[self setSearchResults_2:array];
[array release], array = nil;
}
[[self searchResults_2] removeAllObjects];
//test end
if ([[self savedSearchTerm] length] != 0)
{
for (NSString *currentString in glossaryListItems_2)
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self searchResults] addObject:currentString]; //add words to search results array
}
}
for (NSString *currentString in glossaryKeywords)
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self searchResults_2] addObject:currentString]; //add keywords to search results 2 array
}
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == [[self searchDisplayController] searchResultsTableView]){
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
//test
NSString *searchedValue;
NSString *searchedValue_2;
if ([searchResults count] != 0) {
@try {
searchedValue = [searchResults objectAtIndex:indexPath.row]; //typed value
}
@catch (NSException* ex) {
NSLog(@\"exception catched on SR1: %@\",ex);
searchedValue = [searchResults objectAtIndex:0];
}
}
if ([searchResults_2 count] != 0) {
@try {
searchedValue_2 = [searchResults_2 objectAtIndex:indexPath.row]; //typed value
}
@catch (NSException* ex) {
NSLog(@\"exception catched on SR2: %@\",ex);
searchedValue_2 = [searchResults objectAtIndex:0];
}
}
//test end
//let's retrieve short description from DB - begin
sqlite3 *db;
int dbrc; // database return code
ikoi_2AppDelegate *appDelegate = (ikoi_2AppDelegate*)
[UIApplication sharedApplication].delegate;
const char* dbFilePathUTF8 = [appDelegate.dbFilePath UTF8String];
dbrc = sqlite3_open (dbFilePathUTF8, &db);
if (dbrc) {NSLog (@\"couldn't open db:\");}
sqlite3_stmt *dbps;
NSString *queryStatementNS;
if (([searchResults count] == 0) && [searchResults_2 count] != 0){
queryStatementNS = [NSString stringWithFormat:@\"SELECT * FROM glossary WHERE keywords LIKE \\"%@\\"\",searchedValue_2];
}else if (([searchResults count] != 0) && [searchResults_2 count] == 0) {
queryStatementNS = [NSString stringWithFormat:@\"SELECT * FROM glossary WHERE word LIKE \\"%@\\"\",searchedValue];
}else if (([searchResults count] != 0) && [searchResults_2 count] != 0) {
queryStatementNS = [NSString stringWithFormat:@\"SELECT * FROM glossary WHERE word LIKE \\"%@\\" OR keywords LIKE \\"%@\\"\",searchedValue,searchedValue_2];
}
const char *queryStatement = [queryStatementNS UTF8String];
sqlite3_prepare_v2 (db, queryStatement, -1, &dbps, NULL);
NSLog(@\"query : %@\",queryStatementNS);
while (sqlite3_step (dbps) == SQLITE_ROW) {
NSString *db_word = [[NSString alloc] initWithUTF8String: (char*) sqlite3_column_text (dbps,1)];
NSString *db_keywords = [[NSString alloc] initWithUTF8String: (char*) sqlite3_column_text (dbps, 2)];
cell.textLabel.text = db_word;
cell.detailTextLabel.text = [NSString stringWithFormat:@\"Synonyms : %@\",db_keywords];
[db_word release];
[db_keywords release];
}
sqlite3_finalize (dbps);
sqlite3_close(db);
//let's retrieve short description from db - end
}