android SQLiteDatabase.Update()返回2,为什么?

android SQLiteDatabase.Update()返回2,为什么?,android,sql,sqlite,Android,Sql,Sqlite,我有我的数据库,我查询它的所有项目 项目清单如下: Type- Coffee: Name- Cafe Latte Type- Coffee: Name- Flavoured Latte Type- Coffee: Name- Mocha Type- Coffee: Name- Americano Type- Coffee: Name- Short Black Type- Coffee: Name- Flat White Type- Coffee: Name- Espresso Type- Cof

我有我的数据库,我查询它的所有项目

项目清单如下:

Type- Coffee: Name- Cafe Latte
Type- Coffee: Name- Flavoured Latte
Type- Coffee: Name- Mocha
Type- Coffee: Name- Americano
Type- Coffee: Name- Short Black
Type- Coffee: Name- Flat White
Type- Coffee: Name- Espresso
Type- Coffee: Name- Espresso Con Panna
Type- Coffee: Name- Espresso Machiato
Type- Coffee: Name- Espresso Affogato
Type- Coffee: Name- Pot Of Coffee
当我调用这个函数时:

public int EditItem(MenuItem menuItem){
      ContentValues itemNewValues = new ContentValues();
      //itemNewValues.put(ITEM_TYPE,menuItem.getType());
      itemNewValues.put(ITEM_NAME,menuItem.getName());
      itemNewValues.put(ITEM_REGPRICE,menuItem.getRegPrice());
      itemNewValues.put(ITEM_LARGEPRICE,menuItem.getLargePrice());
      String[] args = new String[1];
      args[0]= menuItem.getName();
      return db.update(DATABASE_TABLE, itemNewValues,ITEM_NAME+"=?", args);
}

Log.i("TAG","updating (no of entries edited: " +localDBHandler.EditItem(new MenuItem("Coffee", "Flavoured Latte", "9.90","2.45")));
它返回“已编辑的条目数:2”

但当我再次打印表格时,它是完全相同的

哦,这是我的创建表声明:

// SQL Statement to create a new database.
  private static final String DATABASE_CREATE = "create table " + 
    DATABASE_TABLE + " (" + 
    ITEM_TYPE + " text not null, " +
    ITEM_NAME + " text not null, " +
    ITEM_REGPRICE + " text not null, " +
    ITEM_LARGEPRICE + " text not null);";

这让我很烦恼,因为我不想看到不必要的更改出现在我刚才没有看到的地方。

看看你的模式。如果
db.update()
返回
2
,则它更新了表中的两行,因此
whereClause
匹配两行。出于调试目的,请使用相同的
whereClause
查询该表并查看其返回的内容。您可能需要修改模式和/或添加搜索条件以缩小结果集。

包括您的模式。出于调试目的,您可能希望在同一whereClause上查询db。是的,我得到了架构,并接受了您的建议在同一whereClause上查询db,结果发现它在两个不同的类别下运行,第二个类别我还没有实现,因此它在我的应用程序中从未被可视化,如果你把它做成一个答案,那就把它标记为我接受的答案:)我把它扩展了一点,使它更普遍适用。您可能仍然希望在问题中包含您的模式(
createtable
语句),以帮助大家跟进。