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);";
它困擾着我,因爲我不希望發生意外情況,進一步示出上下,我只是沒有剛纔看到線做。
包含您的模式。出於調試目的,您可能想要在相同的whereClause上查詢db。 – 323go
是的,我得到了架構,並採取了你的意見,以查詢數據庫在相同whereClause,它發現它在兩個不同的類別下,它的第二個我還沒有實現,所以它永遠不會在我的應用程序中可視化,如果你把它作爲一個答案,它將其標記爲我接受的答案:) –
我擴大了這一點,使其更普遍適用。你可能還想在你的問題中包含你的模式('CREATE TABLE'語句)來幫助人們遵循。 – 323go