我能够成功创建和访问我的数据库。但是,当我稍后需要更改属性的类型时,我修改了项目的文件夹数据库,然后将新数据库添加到 Xcode。当我现在运行我的应用程序时(尽管我已经从模拟器中删除了应用程序的目录),我仍然得到我的旧数据库!
我什至尝试以编程方式更改表,如下所示:
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"TTSData.sql"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
//
sqlite3_stmt *statement;
if(sqlite3_open([defaultDBPath UTF8String], &database) == SQLITE_OK)
{
NSString *updateSQL = [NSString stringWithFormat: @"ALTER TABLE Patient ALTER COLUMN Result DOUBLE"];
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:@"" message:@"Success" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
alert=nil;
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Not Altered" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
alert=nil;
}
sqlite3_finalize(statement);
sqlite3_close(database);
}
但我仍然得到我的旧数据库。有谁知道我在这里可能做错了什么?