title: Android - SQLite Comparing system date to date in database
body: <p>The basic idea of what I want to achieve is to make a comparison between the current Android system date and an existing date in a SQlite database.</p>
  
  <p>The idea is to 1.) If the database does not contain contain a entry with today's date, then allow new entry</p>
  
  <p>2.) If the database already contains an entry from today's date, then revoke entry and output error message.</p>
  
  <p>My DBAdapter currently has a method that does the following:</p>
  
  <pre><code>public Cursor getDate(String date) {
  String where = KEY_DATE + "=" + date;
  Cursor c =  db.query(true, DATABASE_TABLE, ALL_KEYS, 
                  where, null, null, null, null, null);
  if (c !=null) {
      c.moveToFirst();
  }
  return c;
  }
  </code></pre>
  
  <p>and the method i'm using to make the comparison is:</p>
  
  <pre><code>public void addRecord (View view){
      db.open();
      Cursor cursor = db.getDate(dateString);
  
      if (cursor.moveToFirst()){
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setTitle("Date"); 
          builder.setMessage("Entry for today exists, would you like to update this instead?"); builder.setPositiveButton("OK", null);
          @SuppressWarnings("unused")
          AlertDialog dialog = builder.show();
          db.close();
      }
      else{
  
  Do other work..
  </code></pre>
  
  <p>both Date's used for comparison is formatted using this code:</p>
  
  <pre><code>long longDate = System.currentTimeMillis();
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  String dateString = sdf.format(longDate);
  </code></pre>
  
  <p>where I'm simply calling 'dateString'</p>
  
  <p>My trouble is that it doesn't perform the correct checks and skips my else statement completely even tho i know there is an existing 'date' in the database. Is my SQL statement correct?</p>