title: Android SQLite - what does SQLiteDatabase.replace() actually do?
body: <p>I need to do a INSERT or UPDATE IF EXIST type of procedure with my database. I read that <code>.replace()</code> was the way to go. It inserts new records just fine, but if the record already exists, it doesn't appear to update it.</p>
  
  <p>I have something like this:</p>
  
  <pre><code>ContentValues values = new ContentValues();
  values.put(ID, 1);
  values.put(NAME, "bob");
  values.put(VISIBLE, true);
  db.replace("peopleTable", null, values);
  </code></pre>
  
  <p>If I run this code when this record isn't in the database, it appears to create the record just fine, as if I did an <code>insert()</code>. But if I change NAME to "john" or something like that, and run the <code>replace()</code> again, it doesn't appear to update the record.</p>
  
  <p>According to the docs, here is the syntax:</p>
  
  <pre><code>public long replace (String table, String nullColumnHack, ContentValues initialValues)
  </code></pre>
  
  <p>Why is it called <code>initalValues</code>? Does that mean those values are only used when the record doesn't exist and it's going to be inserted? If so, how do you use the method to update a record? Where do you specify the new values?</p>
  
  <p>If I am misunderstanding what <code>replace()</code> does altogether, can someone explain what it's purpose is?</p>