2013-08-28 76 views
2

我有我的數據庫,我查詢它的所有項目。android SQLiteDatabase.Update()返回2,爲什麼?

項目的列表是:

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」

但是當我打印出來該表再次是完全一樣的。

哦我的繼承人創建表statment:

// 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);"; 

它困擾着我,因爲我不希望發生意外情況,進一步示出上下,我只是沒有剛纔看到線做。

+1

包含您的模式。出於調試目的,您可能想要在相同的whereClause上查詢db。 – 323go

+0

是的,我得到了架構,並採取了你的意見,以查詢數據庫在相同whereClause,它發現它在兩個不同的類別下,它的第二個我還沒有實現,所以它永遠不會在我的應用程序中可視化,如果你把它作爲一個答案,它將其標記爲我接受的答案:) –

+0

我擴大了這一點,使其更普遍適用。你可能還想在你的問題中包含你的模式('CREATE TABLE'語句)來幫助人們遵循。 – 323go

回答

1

看看你的模式。如果db.update()返回2,那麼它更新表中的兩行,因此您的whereClause匹配兩行。出於調試目的,使用相同的whereClause查詢表並查看它返回的內容。您可能需要修改模式和/或添加搜索條件以縮小結果集。

相關問題