我在SQLite数据库中进行更新。当我更新单个数据时(意味着它正在更新的数据库字段的AcountName)。但是当我一起更新多个字段时(比如AcountName,UserName,Password,Url,注意任何与AcountName的组合,然后应用程序崩溃在 sql = [NSString stringWithFormat:@“更新UserInfo1设置AcountName =?,UserName = ?,密码=?,Url =?,注意=?其中AcountName ='%@'“,strAcountName]; )
-(void)updateData:(NSString *)AcName :(NSString *)UsrName :(NSString *)Pswd :(NSString *)url :(NSString *)Note
{
sqlite3_stmt *updateStatement = nil;
NSString *sql;
int returnvalue;
sql = [NSString stringWithFormat:@"update UserInfo1 set AcountName=?, UserName=?, Password=?, Url=?, Note=? where AcountName='%@'",strAcountName];
returnvalue = sqlite3_prepare_v2(database, [sql UTF8String], -1, &updateStatement, NULL);
if (returnvalue == 1)
{
NSAssert1 (0,@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_text(updateStatement, 1,[AcName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStatement, 2,[UsrName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStatement, 3,[Pswd UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStatement, 4,[url UTF8String],-1, SQLITE_TRANSIENT);
sqlite3_bind_text(updateStatement, 5,[Note UTF8String], -1, SQLITE_TRANSIENT);
if(sqlite3_step(updateStatement) != SQLITE_DONE )
{
bulDataExist = YES;
[strAcountName retain];
}
else
{
sqlite3_reset(updateStatement);
bulDataExist = NO;
}
sqlite3_finalize(updateStatement);
}
Sent at 6:11 PM on Tuesday
请纠正我。
由于
答案 0 :(得分:1)
我说你在strAcountName中有一些不好的东西。我敢打赌它在你到达之前已经自动释放了。致电
[strAcountName retain]
创建后,然后调用
[strAcountName release]
当你完成它。为什么在成功更新sql后保留它?我认为你那时候会折腾它。