- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected country
NSString *selectedAuthors = [theauthors objectAtIndex:indexPath.row];
//NSLog(selectedAuthors);
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
Details *dvController = [storyboard instantiateViewControllerWithIdentifier:@"Details"]; //Or whatever identifier you have defined in your storyboard
//authorNAme = selectedAuthors.description;
NSString *titleString = [[[NSString alloc] initWithFormat:@"Element number : %d",indexPath.row] autorelease];
authorNAme = titleString;
//Initialize the detail view controller and display it.
//Details *dvController = [[Details alloc] init/*WithNibName:@"Details" bundle:nil*/];
dvController.selectedAuthors = selectedAuthors;
@try {
NSFileManager *fileMgr2 = [NSFileManager defaultManager];
// NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"dictionary.sqlite"];
//NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"authorsDb2.sqlite"];
// NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"FinalDb.sqlite"];
//NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"xxJuridique-FINAL-OK.sqlite"];
NSString *dbPath2 = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"data.sqlite"];
BOOL success = [fileMgr2 fileExistsAtPath:dbPath2];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath2);
}
if(!(sqlite3_open([dbPath2 UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %@", sqlite3_errmsg(db));
}
NSLog(@"access to the second DB is ok");
// const char *sql = "SELECT F_Keyword FROM wordss";
const char *sql2 = "SELECT field7 FROM Sheet1 WHERE field1 = 'titleString' ";
//NSLog(sql2);
sqlite3_stmt *sqlStatement2;
if(sqlite3_prepare(db, sql2, -1, &sqlStatement2, NULL) != SQLITE_OK)
{ NSLog(@"Problem with prepare the db");
NSLog(@"Problem with prepare statement: %@", sqlite3_errmsg(db));
}else{
// while (sqlite3_step(sqlStatement2)==SQLITE_ACCESS_EXISTS) {
NSLog(@"Starting to prepare the result");
Author * author2 = [[Author alloc] init];
NSLog(@"Author 2 created");
author2.genre2 = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement2, 7 )];
NSLog(@"Initialistion of author 2 is ok");
// NSLog(author2.genre);
// authorNAme = author2.genre;
[theauthors addObject:author2];
// }
}
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %@", sqlite3_errmsg(db));
}
@finally {
// sqlite3_finalize(sqlStatement);.
// authorNAme = nil;
sqlite3_close(db);
// authorNAme = Nil;
return theauthors;
}
UIAlertView *messageAlert = [[UIAlertView alloc]
initWithTitle:@"Row Selected" message:titleString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[messageAlert show];
[self.navigationController pushViewController:dvController animated:YES];
}