数据库打开 执行SQL一切正常 但是就是数据库的字段不更新 擦了!找了好久,求大神们看看!!!
if ([self openDB]) {
//char *errormsg;
sqlite3_stmt *statement;//这相当一个容器,放转化OK的sql语句
NSString *updateSql = [NSString stringWithFormat:@"UPDATE Character SET CH_IsLook = 1 WHERE id = %i",studyId];
const char *sql = [updateSql UTF8String];
//sqlite3_exec(_database, "BEGIN TRANSACTION", NULL, NULL, &errormsg);
int success = sqlite3_prepare_v2(_database, sql, -1, &statement, NULL);
if(success != SQLITE_OK){
MyLog(@"更新数据库错误");
sqlite3_close(_database);
return NO;
}
//sqlite3_bind_int(statement, 1, studyId);
//执行SQL语句。这里是更新数据库
success = sqlite3_step(statement);
//sqlite3_exec(_database, "COMMIT", NULL, NULL, &errormsg);
//如果执行失败
if (success == SQLITE_ERROR) {
NSLog(@"Error: 更新数据库错误");
//关闭数据库
sqlite3_close(_database);
return NO;
}
//释放statement
sqlite3_finalize(statement);
//执行成功后依然要关闭数据库
sqlite3_close(_database);
return YES;
}
打印出的SQL在数据库执行时可以的,是不是上面调用执行更新额方法不对???
2014-09-05 11:27:40.903[7836:60b] 0
(lldb) po sql
"UPDATE Character SET CH_IsLook = 1 WHERE id = 1"
返回的执行码是 101 我对了一下 是说SQL执行成功了啊
if ([self openDB]) {
//char *errormsg;
sqlite3_stmt *statement;//这相当一个容器,放转化OK的sql语句
NSString *updateSql = [NSString stringWithFormat:@"UPDATE Character SET CH_IsLook = 1 WHERE id = %i",studyId];
const char *sql = [updateSql UTF8String];
//sqlite3_exec(_database, "BEGIN TRANSACTION", NULL, NULL, &errormsg);
int success = sqlite3_prepare_v2(_database, sql, -1, &statement, NULL);
if(success != SQLITE_OK){
MyLog(@"更新数据库错误");
sqlite3_close(_database);
return NO;
}
//sqlite3_bind_int(statement, 1, studyId);
//执行SQL语句。这里是更新数据库
success = sqlite3_step(statement);
//sqlite3_exec(_database, "COMMIT", NULL, NULL, &errormsg);
//如果执行失败
if (success == SQLITE_ERROR) {
NSLog(@"Error: 更新数据库错误");
//关闭数据库
sqlite3_close(_database);
return NO;
}
//释放statement
sqlite3_finalize(statement);
//执行成功后依然要关闭数据库
sqlite3_close(_database);
return YES;
}
打印出的SQL在数据库执行时可以的,是不是上面调用执行更新额方法不对???
2014-09-05 11:27:40.903[7836:60b] 0
(lldb) po sql
"UPDATE Character SET CH_IsLook = 1 WHERE id = 1"
返回的执行码是 101 我对了一下 是说SQL执行成功了啊