Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void insertCaloriesCountIntoDB(String date,int caloriesCount) {
- SQLiteDatabase db = this.getWritableDatabase();
- //проверяю есть ли запись с таким именем в таблице
- String query ="SELECT * FROM TABLENAME WHERE date = "+date;
- Cursor cursor =db.rawQuery(query,null);
- if(cursor.getCount()==0){
- //если нету записываю
- String insert ="INSERT INTO TABLENAME (date,calcount) VALUES (" + date + ","+ caloriesCount + ")";
- db.execSQL(insert);
- cursor.close();
- db.close();
- }else{
- //если есть обновляю
- String update ="UPDATE TABLENAME SET calcount = calcount + "+caloriesCount+" WHERE date = "+date;
- db.execSQL(update);
- cursor.close();
- db.close();
- }
- public int getCaloriesCount(String date){
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor cursor=db.rawQuery("SELECT calcount FROM TABLENAME where date = ?", new String[]{date});
- while (cursor.moveToNext()) {
- calCount = cursor.getInt(0);
- }
- return calCount;
- }
Add Comment
Please, Sign In to add comment