mercredi 7 janvier 2015

Why my method is not working properly?

I have a database that represents shop stock. The problem is, that the method purchase() doesn't work and I don't know why. Basically, I want from it to open the database, get a specific value from index (everything orks until this point) and update that value by adding 1 and updating database. But it doesn't show any errors when executiong, it's simply not working. Here is my code for purchasing the items.



public void purchase(int ID){
int index = numberOfLives();
ContentValues cv = new ContentValues();
cv.put(fItemNumberOfPurchases, index);
sqLiteDatabase.update(tTableName, cv, fItemID+"=?", new String []{String.valueOf(ID)});
}


here is numberOfLives method:



public int numberOfLives(){
int ID = 1;
sqLiteDatabase = this.getWritableDatabase();
String[] mySearch = new String[]{String.valueOf(ID)};
Cursor myCursor = sqLiteDatabase.rawQuery("SELECT "+ fItemNumberOfPurchases +" FROM "+ tTableName +" WHERE "+ fItemID +"=?",mySearch);
myCursor.moveToFirst();
int index = myCursor.getColumnIndex(fItemNumberOfPurchases);
index = index +3;
myCursor.close();
return index;
}


and this is how I purchase the stuff:



lives.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myDB.purchase(1);
int abc = myDB.numberOfLives();
price1.setText(String.valueOf(abc));
}
});


where is the problem ?


Aucun commentaire:

Enregistrer un commentaire