1
Hello...
//selecionar valores da tabela:
public Cursor IMC(){
Cursor cursor;
String[] campos = {"SELECT (peso/(altura*altura)) FROM medidas WHERE codigo = (SELECT codigo FROM medidas ORDER BY codigo DESC LIMIT 1)"};
db = banco.getReadableDatabase();
cursor = db.query("medidas", campos, null, null, null, null, null, null);
if(cursor!=null){
cursor.moveToFirst();
}
db.close();
return cursor;
}
In Sqlexpert the SELECT looking for only a column or a simple operation as weight+height works, but this in the code above returns 0. I’ve found that you are creating the database and saving the values.
//mostrar o resultado do SELECT em um TextView
public void resultadoIMC() {
BancoController crud = new BancoController(getBaseContext());
Cursor cursor = crud.IMC();
TextView tv = (TextView) findViewById(R.id.txtresultado_imc);
tv.setText(cursor.getString(cursor.getColumnIndex(String.valueOf(0))));
}
In this code returns no value, even changing the SELECT to fetch the value of a single column (In Sqlexpert the SELECT works).
Does anyone have any idea what’s wrong???