title: android sqlite unique insert
body: <p>Just a simple SQLite question...</p>
  
  <p>I've created a table like this:<code>CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT, column1 TEXT, column2 TEXT, UNIQUE (column1, column2))</code>
  (I also tried it with the extension <code>ON CONFLICT REPLACE</code>)</p>
  
  <p>But if I call my insert method on the second time with the same values, they will be added. E.g.</p>
  
  <pre><code>insert("one", "two"); 
  insert("one", "two");
  </code></pre>
  
  <p>fills the table like this:</p>
  
  <pre><code>1 | one | two
  2 | one | two
  </code></pre>
  
  <p>but it should look like this after the second call:</p>
  
  <pre><code>1 | one | two
  </code></pre>
  
  <p>That's my insert function:</p>
  
  <pre><code>public void insert(String a, String b){
      ContentValues contentValues = new ContentValues();
      contentValues.put("column1", a);
      contentValues.put("column2", b);
      try {
          //database.insertWithOnConflict("mytable", null, contentValues, SQLiteDatabase.CONFLICT_IGNORE);
          //database.insertWithOnConflict("mytable", null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
          database.insertOrThrow("mytable", null, contentValues);
      } catch (SQLiteConstraintException e) {
          Log.e("insert", "SQLException: " + e.getLocalizedMessage());
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>if I call </p>
  
  <pre><code>insert("one", "two"); 
  insert("three", "two");
  </code></pre>
  
  <p>the table should be filled like this:</p>
  
  <pre><code>1 | one | two
  2 | three | two
  </code></pre>