title: Select Where with SQLite and android
body: <p>Hey i currently have two functions one that prints the entire database as a string and another that is supposed to only get the data when a criteria is met within the "TODO" column of the database, these are as follows.</p>
  
  <pre><code>     public String databaseToString() {
      String dbString = "";
      SQLiteDatabase db = getWritableDatabase();
      String query = "SELECT * FROM " + TABLE_LIST + " WHERE 1";
  
      //Cursor points to a location in your results
      Cursor c = db.rawQuery(query, null);
      //Move to the first row in your results
      c.moveToFirst();
  
      //Position after the last row means the end of the results
      while (!c.isAfterLast()) {
          if (c.getString(c.getColumnIndex("ToDo")) != null) {
              dbString += c.getString(c.getColumnIndex("ToDo"));
              dbString += " ";
              dbString += c.getString(c.getColumnIndex("accFor"));
              dbString += "\n";
          }
          c.moveToNext();
      }
      db.close();
      return dbString;
  }
  </code></pre>
  
  <p>This is the code for the working function that turns the entire database into a string to be printed. Below is the none working function that is supposed to get all values from the database where TODO is equal to the string university which i have called further up in mydatabasemanager app that contains both of these functions</p>
  
  <pre><code> public String UniversityToString() {
      String dbString = "";
      SQLiteDatabase db = getWritableDatabase();
      String query = ("SELECT " + COLUMN_TODO + COLUMN_FOR + " FROM " + TABLE_LIST + " WHERE "+ COLUMN_FOR + "=\"" + University + "\";");
  
      //Cursor points to a location in your results
      Cursor c = db.rawQuery(query, null);
      //Move to the first row in your results
      c.moveToFirst();
  
      //Position after the last row means the end of the results
      while (!c.isAfterLast()) {
          if (c.getString(c.getColumnIndex("ToDo")) != null) {
              dbString += c.getString(c.getColumnIndex("ToDo"));
              dbString += " ";
              dbString += c.getString(c.getColumnIndex("accFor"));
              dbString += "\n";
          }
          c.moveToNext();
      }
  
      db.close();
      return dbString;
  }
  </code></pre>
  
  <p>This code here causes my app to crash upon opening the activity that calls it i am just wondering how i would fix this to correctly select the data that i require.</p>