title: SQLite create table with UNIQUE combination of columns
body: <p>I have looked through several sites for any useful documentation and have come up empty. The flow charts from the official site might as well be greek and examples I have attempted from other relevant posts on this site have gotten me errors. I am writing a simple app to place user input in a database, however I need a <strong>combination of 2 columns to be unique</strong>. From what I have seen this can be accomplished with UNIQUE or PRIMARY KEY. <strong>I also need some way of capturing the error to Toast the user that their input is faulty</strong>. I know that I can do this in the Java side easily enough yet I would prefer not to loop through the table on every proposed insert. </p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>db.execSQL("CREATE TABLE inventory (category TEXT, itemNum TEXT, quantity INTEGER, price REAL, image INTEGER, UNIQUE(category, itemNum) ON CONFLICT FAIL;");
  </code></pre>
  
  <p>The table constructed properly until I added UNIQUE...</p>
  
  <p>Which threw:
  ERROR/SQLiteOpenHelper(1037): android.database.sqlite.SQLiteException: near ";": syntax error: CREATE TABLE inventory (category TEXT, itemNum TEXT, quantity INTEGER, price REAL, image INTEGER, CONSTRAINT unq UNIQUE(category, itemNum) ON CONFLICT FAIL;</p>
  
  <p>EDIT:</p>
  
  <p>... fill <em>ContentValues values</em> with user input.</p>
  
  <pre><code>try{
  db.getWritableDatabase().insert(DatabaseHelper.TABLE_NAME, DatabaseHelper.CATEGORY, values);
  fillItemNumbers();  // Updates screen       
  }
  catch(SQLiteConstraintException e)
  {
  Toast
  .makeText(this, "User error",Toast.LENGTH_LONG)
  .show();            
  }
  </code></pre>