title: Returning sqlite query as cursor or object/list
body: <p>When I started my app years ago, I did some tutorials and always did my queries to the database returning the cursor (without closing it):</p>
  
  <pre><code>public Cursor querySingleId(String szId) {
      SQLiteDatabase db = getWritableDatabase();
      return db.query(TABLE_ADR, szGetTableEntries, _ID + " = ?", new String[]{szId}, null, null, null);
  }   
  </code></pre>
  
  <p>Now I am refactoring my code to MVVM and added models, so I changed my code to this:</p>
  
  <pre><code>public Card querySingleId(String szId) {
      SQLiteDatabase db = getWritableDatabase();
      Cursor c1 = db.query(TABLE_ADR, szGetTableEntries, _ID + " = ?", new String[]{szId}, null, null, null);
      c1.moveToFirst();
  
      return new Card(c1.getString(c1.getColumnIndex(DbHandler.NAME)),
                      c1.getString(c1.getColumnIndex(DbHandler.STREET)),
                      c1.getString(c1.getColumnIndex(DbHandler.CITY)));
  }
  </code></pre>
  
  <p>I read that cursors should always be closed (memory leak). Which is the best/most conform approach to return my data from the database? I'm also unsure if there are multiple results, should I stay with a cursor or change to a list?</p>
  
  <pre><code>public List&lt;Card&gt; queryAll() {
      SQLiteDatabase db = getWritableDatabase();
      Cursor c1 = db.query(TABLE_ADR, szGetTableEntries, null, null, null, null, null);
      List&lt;Card&gt; list = new ArrayList&lt;&gt;();
  
      if(c1.moveToFirst()){
          do{
              list.add(new Card(c1.getString(c1.getColumnIndex(DbHandler.NAME)),
                                c1.getString(c1.getColumnIndex(DbHandler.STREET)),
                                c1.getString(c1.getColumnIndex(DbHandler.CITY))));
          } while(c1.moveToNext());
      }
      c1.close();
      return list;
  }
  </code></pre>
  
  <p>Is this all just a matter of taste or are there reasons why it should return a cursor or a list/object? Depending where in my code I need the data, a list or a cursor is more convenient. 
  I'm just not sure what is the correct approach in sqlite queries. There are so many code examples and but it seems most is copy/paste without really digging into the topic.</p>