@Test
  public void testReplaceIsReplacing() throws Exception {
    final String query = "SELECT first_column FROM table_name WHERE id = ";
    String stringValueA = "column_valueA";
    String stringValueB = "column_valueB";
    long id = 1;

    ContentValues valuesA = new ContentValues();
    valuesA.put("id", id);
    valuesA.put("first_column", stringValueA);

    ContentValues valuesB = new ContentValues();
    valuesB.put("id", id);
    valuesB.put("first_column", stringValueB);

    long firstId = database.replaceOrThrow("table_name", null, valuesA);
    Cursor firstCursor = executeQuery(query + firstId);
    assertThat(firstCursor.moveToNext()).isTrue();
    long secondId = database.replaceOrThrow("table_name", null, valuesB);
    Cursor secondCursor = executeQuery(query + secondId);
    assertThat(secondCursor.moveToNext());

    assertThat(firstId).isEqualTo(id);
    assertThat(secondId).isEqualTo(id);
    assertThat(firstCursor.getString(0)).isEqualTo(stringValueA);
    assertThat(secondCursor.getString(0)).isEqualTo(stringValueB);
  }
Esempio n. 2
0
 @Override
 public void addClient(String mac, String ip) {
   ContentValues cv = new ContentValues(2);
   cv.put(DatabaseHelper.DATABASE_MAC, mac);
   cv.put(DatabaseHelper.DATABASE_IP, ip);
   SQLiteDatabase db = mDatabaseH.getWritableDatabase();
   try {
     db.replaceOrThrow(DatabaseHelper.DATABASE_TABLE, null, cv);
   } catch (SQLException e) {
     Log.e(AperiMainActivity.TAG, "Could not add/replace [" + mac + "]:\n" + e.getMessage());
   }
 }
Esempio n. 3
0
 public void replace(String item) {
   ContentValues values = new ContentValues();
   values.put("item", item);
   _db.replaceOrThrow(ITEMS_TABLE, null, values);
 }