繁体   English   中英

Xcode 4.3.2上的错误<Attempt to write a readonly database>

[英]Error on Xcode 4.3.2 <Attempt to write a readonly database>

我是iPhone编程的新手。.我不断收到错误消息,我不知道如何更改SQLite的权限

更新时出错。 尝试编写一个只读数据库

以下是我的编码

NSString * filePath = [[NSBundle mainBundle] pathForResource:@“ card” ofType:@“ sqlite”];
sqlite3_stmt *声明;

if(sqlite3_open([filePath UTF8String],&db)== SQLITE_OK)
{
const char * query_stmt =“ UPDATE卡SET isActivate =?”;
if(sqlite3_prepare_v2(db,query_stmt,-1,&statement,NULL)!= SQLITE_OK)
{
NSAssert1(0,@“创建更新语句时出错。'%s'”,sqlite3_errmsg(db));
}
}


sqlite3_bind_int(statement,1,1);
if(SQLITE_DONE!= sqlite3_step(statement))
{
NSLog(@“更新时出错。%s”,sqlite3_errmsg(db));
}

sqlite3_finalize(声明);
sqlite3_close(db);

希望有人能帮助我,因为这确实让我感到沮丧。

您需要将sql文件复制到缓存目录中才能正确使用。
这是我的一些代码:

NSString *sqlFile = @"database.sql";
NSArray *cachePath= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDir = [cachePathobjectAtIndex:0];
databasePath = [cacheDirstringByAppendingPathComponent:sqlFile];

NSFileManager *fileManager = [NSFileManager defaultManager];
// Copy the database sql file from the resourcepath to the documentpath
if (![fileManager fileExistsAtPath:databasePath]) {
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:sqlFile];
    NSError *error;
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:&error];
    if (error != nil) {
        NSLog(@"[Database:Error] %@", error);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM