2013-07-22 40 views
0

将新项目插入表格可以很好地工作,但更新不起作用。FMDB executeUpdate不会改变数据库

我正在使用以下语句来更新我的数据库。尚未包装成一个NSNumber

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]; 

一切都是一个NSString(全部注销如预期)。

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

下一次我读我的数据库,这些变化尚未作出。

任何想法?

+0

我希望数据库不在应用程序包中,但在可写的地方... – 2013-07-22 12:24:51

+0

数据库在设备上 - /var/mobile/Applications/*/Documents/FeedItems.db,就像我说的,我可以插入它,只是不更新​​已经存在的项目。 – Bongeh

+0

跟踪执行似乎也正在注销正在被解雇的语句 – Bongeh

回答

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]; 

这怎么..没有工作,直到我已经从字符串对象除去周围的'的。

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); 
    } 
+0

你不能用'?'在[NSString stringWithFormat:]中,如果你想这样做,你必须使用%@。除了调用executeUpdate两次,没有保存任何更改,这基本上与我所做的不同。 – Bongeh