在使用此代码复制数据库时,我不断收到错误“sqlite step failed:attest to write a readonly database”:
-(void)createEditableCopyOfDatabaseIfNeeded
{
// Testing for existence
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath =
[documentsDirectory stringByAppendingPathComponent:@"Money.sqlite"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success)
return;
// The writable database does not exist, so copy the default to
// the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"Money.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath
toPath:writableDBPath
error:&error];
if(!success)
{
NSAssert1(0,@"Failed to create writable database file with Message : '%@'.",
[error localizedDescription]);
}
}
我在appdelegate中使用上述代码
而这个:
NSString *writableDBPath =
[[NSBundle mainBundle] pathForResource:@"Money"
ofType:@"sqlite"];
在viewcontroller.m中
我在用
http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/
我做错什么了?
这是一次又一次…它以前工作得很好,但问题又开始了。