FMDB executeUpdate不改变数据库

时间:2013-07-22 12:22:10

标签: iphone ios sqlite fmdb

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

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

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错误(成功bool返回TRUE)

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

有什么想法吗?

2 个答案:

答案 0 :(得分: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];

直到我从字符串对象周围删除了's才行。

答案 1 :(得分: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);
  }