it seems the SQLiteDatabase.query() method doesn't replace my ?s in the where clause with the selectionArgs:
String[] columns = new String[] { Table.COL_WEIGHT };
String[] selectionArgs = new String[] { Table.COL_DATE, Table.COL_DATE,
Table.TABLE_NAME };
String sqlquery = SQLiteQueryBuilder.buildQueryString(false, Table.TABLE_NAME,
columns, "?=(SELECT max(?) FROM ?)", null, null, null, null);
Cursor cursor = mDb.rawQuery(sqlquery, selectionArgs);
This thows the following exception:
FATAL EXCEPTION: main
java.lang.RuntimeException:
Unable to start activity ComponentInfo{Activity}:
android.database.sqlite.SQLiteException: near "?":
syntax error (code 1): , while compiling:
SELECT Weight FROM Bodyfat WHERE ?=(SELECT max(?) FROM ?)
While:
String sql = String.format("SELECT %s FROM %s WHERE %s=(SELECT max(%s) FROM %s)",
Table.COL_WEIGHT, Table.TABLE_NAME, Table.COL_DATE,
Table.COL_DATE, Table.TABLE_NAME);
//SELECT Weight FROM Bodyfat WHERE Date=(SELECT max(Date) FROM Bodyfat)
Cursor cursor = mDb.rawQuery(sql, null);
Works like expected. Am I using query() and it's selectionArgs correctly?