0

向表中插入新项目非常有效,但更新没有效果。

我正在使用以下语句来更新我的数据库。

BOOL success = [fmDB executeUpdate:@"UPDATE activities SET type = ?, author = '?', 
                time = '?', location = '?', node = '?', nodeID = ? 
                WHERE itemid = ?", [NSNumber numberWithInt:itemType], author, 
                time, location, node, [NSNumber numberWithInt:nodeID], 
                [NSNumber numberWithInt:itemID], nil];

没有被包装成 NSNumber 的所有东西都是一个 NSString (它们都按预期注销)。

运行命令时收到 0 个错误(成功布尔返回 TRUE)

下次我阅读我的数据库时,尚未进行更改。

有任何想法吗?

4

2 回答 2

2

好的,所以我让它工作..一些如何..

 BOOL success = [fmDB executeUpdateWithFormat:@"UPDATE activites 
   SET type = %@, node = %@, time = %@, location = %@, author = %@, 
   nodeID = %@ WHERE itemid = %@", [NSNumber numberWithInt:itemType], 
   node, time, location, author, [NSNumber numberWithInt:nodeID], 
   [NSNumber numberWithInt:itemID], nil];

在我从字符串对象周围删除 ' ' 之前,这不起作用。

于 2013-07-23T09:31:21.550 回答
0
 if([db open])
 {
    NSString *queryStr ;
    queryStr = [NSString stringWithFormat:@"Update activities SET type = ?, author = '?', 
            time = '?', location = '?', node = '?', nodeID = ? 
            WHERE itemid = ? ",[NSNumber numberWithInt:itemType], author, 
            time, location, node, [NSNumber numberWithInt:nodeID], 
            [NSNumber numberWithInt:itemID]];
    [db executeUpdate:queryStr];
    NSLog(@"UPDATE\n%@",queryStr);
  }
于 2013-07-22T12:41:18.273 回答