samedi 14 février 2015

Android cursor columns

Is is safe to assume that Android cursor only has the columns I requested and returns them in the same order as they are in the select statement, i. e. will the following code always work?



Cursor cursor = db.query("NAMES",
new String[] {"FIRSTNAME", "LASTNAME", "MOBILE"},
"ID = " + requestedId, null, null, null, null, null);

if (cursor.moveToFirst()) {
firstname = cursor.getString(0);
lastname = cursor.getString(1);
mobile = cursor.getString(2);
}


or should I stick to getting column indices explicitly like below because Android SQLite may add some auxiliary data in the cursor returned by query() or change the order of the columns?



firstname = cursor.getString(cursor.getColumnIndex("FIRSTNAME"));
lastname = cursor.getString(cursor.getColumnIndex("LASTNAME"));
mobile = cursor.getString(cursor.getColumnIndex("MOBILE"));

Aucun commentaire:

Enregistrer un commentaire