0

我正在更新 SQLite 数据库。当我更新单个数据时(意味着它正在更新的数据库字段的 AcountName )。但是当我一起更新多个字段时(如 AcountName、UserName、Password、Url,请注意与 AcountName 的任何组合,然后应用程序在sql = [NSString stringWithFormat:@"update UserInfo1 set AcountName=?, UserName=?, Password 处崩溃=?, Url=?, Note=? where 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

请纠正我。

谢谢

4

1 回答 1

1

我会说你在 strAcountName 中有一些不好的地方。我敢打赌它在你拿到它之前就自动发布了。称呼

[strAcountName retain]

创建后,然后调用

[strAcountName release]

当你完成它时。为什么在成功更新sql后保留它?我想你会在那个时候扔掉它。

于 2012-08-21T17:07:13.150 回答