Clause error Where SQLITE

Asked

Viewed 88 times

2

Hi, I have a small problem in the following method:

Future<List> getAllTarefasMediaPrioridade(String status) async{
  Database dbTarefas = await db;
  List<Tarefas> listTarefasMediaPrioridade;
  List listMap2 = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable"); 
  if(status.isEmpty){
    try{
      List listMap = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable"
          " WHERE $prioridadeColumn = Media");
      for(Map m in listMap) listTarefasMediaPrioridade.add(Tarefas.fromMap(m));
    } catch (e){
      e.toString();
    }

    return listTarefasMediaPrioridade;
  }
  else{
    return listTarefasMediaPrioridade = List();
  }
}

When I do : List listMap2 = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable");, he returns me all the data I have in my comic :

inserir a descrição da imagem aqui

Even there is correct, but when I will insert a Where :

final String prioridadeColumn = "prioridadeColumn";
List listMap = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable WHERE $prioridadeColumn = Media");

I get the error: no such column: Media (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM tarefasTable WHERE prioridadeColumn = Media

I can’t identify what’s wrong.

  • 1

    is understanding Media as a column, I think the right one would be SELECT * FROM $tarefasTable WHERE $prioridadeColumn = 'Media'

2 answers

2


You are making a comparison in sql but it should be done using a string in sql.

 List listMap = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable" +
      " WHERE $prioridadeColumn = 'Media'");

The query has to look like this:

SELECT * FROM $tarefasTable WHERE $prioridadeColumn = 'Media'

The problem is the word Media in your application that should be represented as a string in sql.

  • Cool, now it worked, thanks for the help

0

try to change

List listMap = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable"
          " WHERE $prioridadeColumn = Media");

for

List listMap = await dbTarefas.rawQuery("SELECT * FROM $tarefasTable"    +
          " WHERE $prioridadeColumn = Media");
  • Thanks for trying, but this is android studio the error is not that, but thank you

  • In Dart Voce you can break string lines without using +

Browser other questions tagged

You are not signed in. Login or sign up in order to post.