I got this exc_bad_access problem in AppDelegate.m What I did and want is to have multiple sql query. To avoid complexity, I did two blocks (it will have more) and both are querying different table from sql.
-(void)readDataFromDatabase {
// Setup the database object
sqlite3 *database;
// Initialize the budgetobjects Array
Part1Array = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from part1TBL";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
// You can add more rows based on your object
NSString *Part1_Name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *Part1_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
// Create a new Restaurant with the data from the database
Part1 *newPart1 = [[Part1 alloc] initWithName:Part1_Name description:Part1_Description];
// Add the budgetobject to BudgetObjectsrantArray
[Part1Array addObject:newPart1];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
// Setup the database object
sqlite3 *database2;
// Initialize the budgetobjects Array
Part2Array = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from part2TBL";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
// You can add more rows based on your object
NSString *Part2_Name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *Part2_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
// Create a new Restaurant with the data from the database
Part2 *newPart2 = [[Part2 alloc] initWithName:Part2_Name description:Part2_Description];
// Add the budgetobject to BudgetObjectsrantArray
[Part2Array addObject:newPart2];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database2);
}
@end
The exc_bad_access highlighted at the end where
sqlite3_close(database2);