title: Check duplicate's before inserting data in SQLite database
body: <p>Im inserting 3 values into a database on a click of a button, 1 is the insert date, 2 is a number from a editText and the 3rd is the value assigned to the button being clicked(there are six different buttons that can be clicked)</p>
  
  <p>What I want to do is check if the date and number are already in the database the 3rd value does not matter. I cant use unique on any of the columns as I want the number from the editText to be able to be entered again but just not on the same day.</p>
  
  <p>I have got this far...
  and it does not enter any data to database</p>
  
  <p>From MainActivity</p>
  
  <pre><code>    public void onClick_30(View v) {
  
      counter++;
      cnt_bcs30++;
  
      String getCowNum = CowNum.getText().toString();
  
      Cursor C = myDB.dubUpCheck();
      String ddate = C.getString(DBAdapter.COL_DATE);
      String cow = C.getString(DBAdapter.COL_COW);
  
  
      if(C.moveToFirst()){
  
          do {
  
              if(ddate == dateFormat.format(date) &amp;&amp; cow == getCowNum){
          Toast.makeText(getBaseContext(), getCowNum + "Has already been scored today ",
                  Toast.LENGTH_SHORT).show();
              }
          }while (C.moveToNext());
  
  
      }else{
  
  
  
      myDB.insertRow(dateFormat.format(date), getCowNum, 3.0);
  
      Toast.makeText(getBaseContext(), getCowNum + " " + score30,
              Toast.LENGTH_SHORT).show();
      CowNum.clearFocus();
      }
  }
  </code></pre>
  
  <p>From my DBAdapter</p>
  
  <pre><code>            public Cursor dubUpCheck() {
  
      Cursor c = db.query(DATABASE_TABLE, new String []{KEY_DATE, KEY_COW}, null, null,
              null, null, null, null);
      if (c != null) {
          c.moveToFirst();
      }
  
      return c;
  
  }
  </code></pre>
  
  <p>I need to check if there is a row with dateFormat.format(date) and getCowNum but i cant seem to get it to work, not sure if it is due to the way I am storing the date which is a string in the format of dd-MM-yyyy</p>
  
  <pre><code>    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
      Date date = new Date(); 
  </code></pre>
  
  <p>like this, enters data but still allows dupicates</p>
  
  <pre><code>    public void onClick_30(View v) {
  
      counter++;
      cnt_bcs30++;
  
      String getCowNum = CowNum.getText().toString();
  
      Cursor C = myDB.dubUpCheck();
      String ddate = C.getString(DBAdapter.COL_DATE);
      String cow = C.getString(DBAdapter.COL_COW);
  
  
      if(ddate == dateFormat.format(date) &amp;&amp; cow == getCowNum){
          Toast.makeText(getBaseContext(), getCowNum + "Has already been scored today ",
                  Toast.LENGTH_SHORT).show();
          }else{
  
  
  
      myDB.insertRow(dateFormat.format(date), getCowNum, 3.0);
  
      Toast.makeText(getBaseContext(), getCowNum + " " + score30,
              Toast.LENGTH_SHORT).show();
      CowNum.clearFocus();
      }
  </code></pre>
  
  <p>UPD: Another attempt... the else statement is in the wrong place I know but thats not all thats wrong Im guessing</p>
  
  <pre><code>        public void onClick_30(View v) {
  
      counter++;
      cnt_bcs30++;
  
      String getCowNum = CowNum.getText().toString();
  
      Cursor C = myDB.dubUpCheck();
      String ddate = C.getString(DBAdapter.COL_DATE);
      String cow = C.getString(DBAdapter.COL_COW);
  
      if (C.moveToFirst()) {
          do {
              if (ddate.equals(dateFormat.format(date)) &amp;&amp; cow.equals(getCowNum)) {
  
                  Toast.makeText(getBaseContext(),
                          getCowNum + "Has already been scored today ",
                          Toast.LENGTH_SHORT).show();
  
              }
  
          } while (C.moveToNext());
      } else {
  
          myDB.insertRow(dateFormat.format(date), getCowNum, 3.0);
  
          Toast.makeText(getBaseContext(), getCowNum + " " + score30,
                  Toast.LENGTH_SHORT).show();
          CowNum.clearFocus();
      }
  }
  </code></pre>