title: Update database, android
body: <p>I've created a method to update an entry to the database within my android application.</p>
  
  <pre><code> public int updateEntryById(ContentValues diaryValues) {
  
      String  updateWhere = Diary.DiaryItem.COLUMN_NAME_ID + " = " + Diary.DiaryItem.COLUMN_NAME_ID;
      Log.i(TAG, "UpdateWhere query values" + updateWhere);
      SQLiteDatabase db = diaryDbHelper.getWritableDatabase();
      ContentValues updateValues = new ContentValues();
  
      updateValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_TITLE, "");
      updateValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_DATE, "");
      updateValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_TIME, "");
      updateValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_ENTRY, "");
      updateValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_LAT, "");
      updateValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_LONG, "");
  
      Log.i(TAG, "UPDATE" + updateWhere);
      //performs the update
      int count = db.update(
              Diary.DiaryItem.TABLE_NAME, 
              updateValues, 
              updateWhere, 
              null);
  
      return count;
  }
  </code></pre>
  
  <p>A problem I am finding is that the Log.i(TAG, "UpdateWhere query values" + updateWhere); Doesn't actually give the ID rather the _ID = _ID, which is the column name. instead I want it to be where _ID = 1 for example.</p>
  
  <p>Any ideas? Thanks in advance</p>
  
  <pre><code>protected void saveDiaryItem() {
          ContentValues saveValues = new ContentValues();
  
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_ID, mID.getText().toString());
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_TITLE, mTitle.getText().toString());
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_DATE, mDate.getText().toString());
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_TIME, mTime.getText().toString());
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_ENTRY, mEntry.getText().toString());
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_LAT, mLat.getText().toString());
          saveValues.put(Diary.DiaryItem.COLUMN_NAME_DIARY_LONG, mLong.getText().toString());
  
          Log.i(TAG, "About to insert data" + saveValues);
          DAO diarySave = new DAO(getBaseContext());
  
          diarySave.updateEntryById(saveValues);
          Log.i(TAG, "IM BACK!"); 
      }
  </code></pre>