Something really weird has happened to my source code. The application always built successfully, and I always used to be able to launch the application. However recently, the app crashes when I launch it and return the following error in the console:
2009-07-23 20:30:06.390 App[15652:20b] Database Successfully Opened :)
2009-07-23 20:30:06.393 App[15652:20b] *** Assertion failure in -[AppDelegate initializeTableData], /Users/me/Desktop/App/Classes/AppDelegate.m:39
2009-07-23 20:30:06.394 App[15652:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error preparing statement'
2009-07-23 20:30:06.394 App[15652:20b] Stack: (
I don't understand. The app would always launch successfully with no error. But now I get this error. I had backed up my source code along the way and now when I build those older versions, I get the same error. How is this even possible. Can code go bad? If I was able to successfully launch an application before and I go back today and recompile it and it returns an error...THE SAME PIECE OF CODE?
The error seems to point to this piece of code in my AppDelegate file:
enter code -(void)initializeTableData {
entries = [[NSMutableArray alloc] init];
sqlite3 *db = [AppDelegate getNewDBConnection];
sqlite3_stmt *statement = nil;
const char *sql = "select * from dict";
if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL) != SQLITE_OK)
NSAssert1(0,@"Error preparing statement", sqlite3_errmsg(db));
else
{
while(sqlite3_step(statement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aGurmukhi = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
NSString *aShahmukhi = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
NSString *aPOS = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
NSString *aEnglish = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
// Create a new animal object with the data from the database
Entry *entry = [[Entry alloc] initWithName:aGurmukhi shahmukhi:aShahmukhi pos:aPOS english:aEnglish];
// Add the animal object to the animals Array
[entries addObject:entry];
[entry release];
}
}
//release the resources
sqlite3_finalize(statement);
}
+(sqlite3 *) getNewDBConnection{
sqlite3 *newDBconnection;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"pedict.db"];
// Open the database. The database was prepared outside the application.
if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :)");
} else {
NSLog(@"Error in opening database :(");
}
return newDBconnection;
}
It seems to be a problem with the database connection, but I'm still confused over how this is all possible. Please help...I've already waisted six hours debugging, with little success