我想知道当数据库(Coredata)字段发生变化时如何将应用程序重新上传到AppStore的详细信息。因为当我在数据库更改后重建应用程序时会出现崩溃,所以为了避免崩溃,我必须重新安装应用程序。
答案 0 :(得分:0)
步骤1:检查数据库中的新字段 第2步:使用alter query在数据库中添加该列
尝试以下代码并应用合适的逻辑。经过这个反馈我。 很高兴为您提供帮助:)
+(void)alterCountryexitcodeTable{
BOOL isAlterRequired = [self checkColumnExists];
if (!isAlterRequired) {
sqlite3 *database;
sqlite3_stmt *statement;
if(sqlite3_open([kDBPath UTF8String], &database) == SQLITE_OK)
{
NSString *updateSQL = [NSString stringWithFormat: @"ALTER TABLE countries ADD COLUMN countryexitcode TEXT"];
const char *update_stmt = [updateSQL UTF8String];
sqlite3_prepare_v2(database, update_stmt, -1, &statement, NULL);
if(sqlite3_step(statement)==SQLITE_DONE)
{
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"DB altered" message:@"Success" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
// [alert show];
// alert=nil;
}
else
{
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"DB Updation" message:@"DB not Altered" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
// [alert show];
// alert=nil;
}
// Release the compiled statement from memory
sqlite3_finalize(statement);
sqlite3_close(database);
}
}
}
+(BOOL)checkColumnExists
{
BOOL columnExists = NO;
static sqlite3 *database = nil;
sqlite3_stmt *selectStmt = NULL;
if (sqlite3_open([kDBPath UTF8String], &database) == SQLITE_OK) {
DLog(@"BEGIN");
sqlite3_exec(database, "BEGIN", 0, 0, 0);
NSString *sqlStatement = @"select countryexitcode from countries";
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &selectStmt, NULL) == SQLITE_OK)
columnExists = YES;
}
return columnExists;
}
答案 1 :(得分:0)