您好,我已经搜索了很多有关此错误的信息。我发现了一些建议,例如您必须使用sqlite_finalize()语句,并且使用了它。看一下我的代码。

-(void)updatePostingsForLike:(NSString *)postingKey isLiked:(NSString *)isLiked {

  [self initWithDB];
  sqlite3_stmt *stmt;

  if(sqlite3_open([[self dbPath] UTF8String],&(db)) == SQLITE_OK) {

      NSString *str=[@"" stringByAppendingFormat:@"update posting set isLiked='%@' where postKey='%@'",isLiked,postingKey];
      const char *sql=[str cStringUsingEncoding:NSUTF8StringEncoding];
      int status;
      status= sqlite3_prepare_v2(db,sql, -1, &stmt, NULL);

      if(SQLITE_DONE != sqlite3_step(stmt))
      {
          NSLog(@"%s",sqlite3_errmsg(db));

      }

      sqlite3_finalize(stmt);

      [self closeConnection];

  }}

我遵守了所有规则。我只能更新一次记录。仅限第一次。它第二次抛出错误。应该怎么解决?最近两天以来,我一直陷入这样的问题!

最佳答案

尝试这个,

-(void) updatePostingsForLike:(NSString *)postingKey isLiked:(NSString *)isLiked
{

   [self initWithDB];
   sqlite3_stmt *statement;

   if(sqlite3_open([[self dbPath] UTF8String],&db) == SQLITE_OK)
   {
      NSString* query=[NSString stringWithFormat: @"update posting set isLiked='%@' where   postKey='%@'",isLiked,postingKey];
      const char *query_stmt = [query UTF8String];

     if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK)
     {
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            sqlite3_column_text(statement, 0);
        }
        sqlite3_finalize(statement);
     }
    sqlite3_close(db);
  }
}

关于iphone - iPhone中的sqlite中的“数据库已锁定”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11974781/

10-11 16:31