Hi at all, I have a little question, I have a simple app that read a database and display some data, all the app work perfectly but when I change my database from mac and I rebuild&go the database is the old database, not the new. For have the new I have to delete app from simulator (or itouch) and re-build...Where is the mistake?Can you help me?
My doubt is if whrn I put an update in appstore the database was changed.
Here is the code that I use for call database
-(void) path {
// Override point for customization after application launch.
// Setup some globals
databaseName = @"ARGOMENTI.sqlite";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
// Execute the "checkAndCreateDatabase" function
[self checkAndCreateDatabase];
// Execute the "readArgFromDatabaseMat" function
[self readArgFromDatabaseMat];
}
-(void) checkAndCreateDatabase {
// Check if the SQL database has already been saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:databasePath];
// If the database already exists then return without doing anything
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
[fileManager release];
}
}
-(void) readArgFromDatabaseMat {
// Setup the database object
sqlite3 *database;
// Init the argoments Array
array_contenuti = [[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 MAT ";
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
NSString *aID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSString *aMat = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
// Create a new argoments object with the data from the database
ContenutoObject *contenuto = [[ContenutoObject alloc] initWithName:aID Mat:aMat];
// Add the argomen object to the argomens Array
[array_contenuti addObject:contenuto];
[contenuto release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}