I wrote this function in a Helper class for reading a table from my database, and returning it to my controller.
On my viewdidload, i cache this result into a class variable (retain property set) and trying to use that inside a picker view control's delegate method. (titleForRow)
Somehow, I get a EXC_BAD_ACCESS when I try to access the values I boxed into the NSMutableDictionary, in the delegate methods.
+ (NSMutableDictionary*) getAllInterchanges {
NSMutableDictionary *interchanges = NSMutableDictionary alloc init;
NSString *sqlString = NSString stringWithFormat:@"SELECT * FROM Interchanges";
const char *sql = sqlString UTF8String;
sqlite3_stmt *statement;
// Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
// The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
Interchanges ic;
ic.name = NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0);
ic.id = sqlite3_column_int(statement, 1);
NSValue *boxedInterchange = NSValue valueWithBytes:&ic objCType:@encode(Interchanges);
interchanges setObject:boxedInterchange forKey:ic.id;
}
}
// "Finalize" the statement - releases the resources associated with the statement.
sqlite3_finalize(statement);
interchanges autorelease;
return interchanges;
}
I even tried commenting out the last autorelease statement. Still it's giving me the same exception...
Please help...