我能够成功地创建并访问我的数据库。但是,当我稍后需要更改属性的类型时,我修改了项目的文件夹数据库,然后将新数据库添加到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);
}但我仍然可以使用我的旧数据库。有谁知道我可能做错了什么吗?
发布于 2012-07-20 01:53:41
您不允许更改资源中的数据库。:(
https://stackoverflow.com/questions/11566273
复制相似问题