0
Personal I am trying to carry out the selection of a list of data in the database Sqlite, using the following code snippet, the selection in the form that is made below is already working well. Plus, it only works when dates are inserted in a static way or at the code level, but I would like the dates to be entered by the user himself through an Edittext.
My idea is to pass the starting date and the dataFinal as Parameters of the method, how to perform this passage I already know, as a test I am doing this at code level is no longer working.
The date is stored with type VARCHAR (String) in the database.
//Cria a tabela do banco de dados
public void onCreate(SQLiteDatabase db) {
String tabela = "CREATE TABLE IF NOT EXISTS dados(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, data VARCHAR NOT NULL, hora VARCHAR NOT NULL , temperatura VARCHAR NOT NULL, umidadeAr VARCHAR NOT NULL, umidadeSolo VARCHAR NOT NULL, velVento VARCHAR NOT NULL, pressao VARCHAR NOT NULL, altitude VARCHAR NOT NULL, qualidadeAr VARCHAR NOT NULL, pressipitacao VARCHAR NOT NULL);";
db.execSQL(tabela);
}
The part where you make the selection is as follows:
public void seleciona(){
String dataInicial = "09-02-2021", dataFinal = "09-02-2021";
String [] columns = {"data", "hora", "temperatura", "umidadeAr", "umidadeSolo", "velVento", "pressao", "altitude", "qualidadeAr", "pressipitacao"};
//String consulta = " data BETWEEN " + dataInicial + " AND " + dataFinal ;
String consulta = " data BETWEEN '10-02-2021' AND '10-02-2021' ";
@SuppressLint("Recycle") Cursor cursor = getWritableDatabase().query("dados", columns, consulta,null, null, null,null);
while (cursor.moveToNext()){
Dados dados = new Dados();
dados.setData(cursor.getString(0));
dados.setHora(cursor.getString(1));
dados.setTemperatura(cursor.getString(2));
dados.setUmidadeAr(cursor.getString(3));
dados.setUmidadeSolo(cursor.getString(4));
dados.setVel_Vento(cursor.getString(5));
dados.setPressao(cursor.getString(6));
dados.setAltitude(cursor.getString(7));
dados.setQualidadeAr(cursor.getString(8));
dados.setPressipitacao(cursor.getString(9));
Log.i("Resultado", "Range de dados: " + dados.getData());
Log.i("Resultado", "Range de dados: " + dados.getHora());
Log.i("Resultado", "Range de dados: " + dados.getTemperatura());
}
}
In the way it is there selects the data, but I wanted to declare a variable that it receives the date entered by the user and is passed as a parameter to the SELECT command, only when placing the date passed to the start date and the given end passed to dataFinal it not executed.
Could someone tell me what I might be doing wrong and give me some solution????