【发布时间】:2014-07-13 01:35:04
【问题描述】:
我正在使用 FMDatabase 处理一个 sqlite 数据库应用程序。
我想更新位于主包中的数据库表
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:db_name];
包含位于文档目录中的数据库中的数据
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *db_Path = [docsPath stringByAppendingPathComponent:db_name];
我多次尝试在“默认”数据库上执行 UPDATE 查询,但它说它已被锁定。所以我考虑在文档目录中使用名称 db_name_cp 处理它并对其进行处理。
NSString *cpPath = [documentsDirectory stringByAppendingPathComponent:@"db_name_cp.sqlite"];
success = [fileManager fileExistsAtPath:cpPath];
if (success){
//remove the existing one
[fileManager removeItemAtPath:cpPath error:&error];
}
//create the copy of the "main bundle" database
[fileManager copyItemAtPath:default_database.dbPath toPath:cpPath error:&error];
然后我尝试对复制的数据库执行 UPDATE,但如果我对其执行 SELECT,它不会更新,如果我在 phpMyAdmin 或 SQLiteManager 上运行查询,它会更新记录。
有什么想法吗?也许我在设备目录上处理它们是错误的。
非常感谢
【问题讨论】:
-
您不能对应用中的任何内容进行更改,这显然包括应用的 mainBundle。
-
是的,我用来对存储在 doc 目录中的数据库执行 UPDATE 查询,它们工作正常。
标签: ios objective-c sqlite nsfilemanager fmdb