我是iphone编程的新手.. 我一直在收到错误 我不知道如何更改SQLite的权限
更新时出错。尝试编写只读数据库
以下是我的编码
NSString * filePath = [[NSBundle mainBundle] pathForResource:@“card”ofType:@“sqlite”];
sqlite3_stmt * statement;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(声明,1,1);
if(SQLITE_DONE!= sqlite3_step(statement))
{
NSLog(@“更新时出错。%s”,sqlite3_errmsg(db));
}sqlite3_finalize(语句);
sqlite3_close(分贝);
希望有人可以帮助我,因为这真让我感到沮丧..
答案 0 :(得分:1)
您需要将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);
}
}