Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public void upDateUser(int money)
  2. {
  3. String selectQuery = "SELECT " + KEY_CREDITS + " from " +
  4. DATABASE_TABLE + " where " + KEY_ROWID + " = " + 0;
  5. Cursor c = ourDatabase.rawQuery(selectQuery, null);
  6. int oldMoney = 0;
  7. if (c.moveToFirst())
  8. {
  9. oldMoney = oldMoney + Integer.parseInt(c.getString(4));
  10. }
  11. ContentValues cvUpdate = new ContentValues();
  12. cvUpdate.put(KEY_CREDITS, (oldMoney + money));
  13. ourDatabase.update(DATABASE_TABLE, cvUpdate, null, null);
  14. }
  15.  
  16. public void upDateUser(int money)
  17. {
  18. String selectQuery = "SELECT " + KEY_CREDITS + " from " +
  19. DATABASE_TABLE + " where " + KEY_ROWID + " = " + 1;
  20. Cursor c = ourDatabase.rawQuery(selectQuery, null);
  21. int oldMoney = 0;
  22. Log.d("com.example.yourapp", c.getCount() + " rows selected");
  23. if (c.moveToFirst())
  24. {
  25. oldMoney = c.getInt(c.getColumnIndex(KEY_CREDITS));
  26. }
  27. ContentValues cvUpdate = new ContentValues();
  28. cvUpdate.put(KEY_CREDITS, (oldMoney + money));
  29. ourDatabase.update(DATABASE_TABLE, cvUpdate, KEY_ROWID + "=?" ,new String[] { "1" });
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement