-(BOOL)updateDevice:(device*) dev{
if([self isDeviceExist:dev]){
sqlite3_stmt *statement;
//1 數據庫地址
const char *dbpath = [_databasePath UTF8String];
//2 打開數據庫
if (sqlite3_open(dbpath, &_dataBase)==SQLITE_OK) {
//3 數據庫語句准備
NSString *insertSql = [NSString stringWithFormat:@"update device set DeviceName = \"%@\",Light1Name = \"%@\", Light2Name = \"%@\" ,Light3Name = \"%@\" where MID = \"%@\"",dev.DeviceName,dev.Light1Name,dev.Light2Name,dev.Light3Name,dev.MID];
NSLog(@"%@",insertSql);
const char *insertsatement = [insertSql UTF8String];
NSLog(@"the char :%s",insertsatement);
if(sqlite3_prepare_v2(_dataBase, insertsatement, -1, &statement, NULL)==SQLITE_OK){
//4 執行數據語句
int result=sqlite3_step(statement);
if (result==SQLITE_DONE) {
NSLog(@"update success");
sqlite3_finalize(statement);
sqlite3_close(_dataBase);
return YES;
}else{
NSLog(@"update failed!");
sqlite3_finalize(statement);
}
}
}
}else{
NSLog(@"device is exist");
}
NSLog(@"Error:%s",sqlite3_errmsg(_dataBase));
sqlite3_close(_dataBase);
return NO;
}
代碼如上,update的sql語句在sqlite中測試沒問題,可是在實機上測試的時候代碼執行沒有報錯,可是數據沒有更新,求解
如果在模擬器上可以更新,在真機上不行,那應該就是訪問權限的問題
你先看看數據庫路徑,是不是放到沙箱內了,可寫的文件要放在document或者library裡面,不能放mainBundle裡