Why isn't my sql query in sqlite/sqlbrite not working with a second condition/multiple WHERE clauses?

97 views Asked by At

I have a query for my Sqlite/Brite databse that takes two conditions. One to check for a selected quarter, and another to make sure an action attribute isn't "delete". When I only have the WHERE clause to check for the selected quarter, I get all the data I want. When I add the WHERE clause to check to make sure it doesn't have a "deleted" attribute, nothing comes back. Nothing should have a deleted attribute so all the same data should come back, but it isn't. Why is this?

Heres the function that's causing me the issues

 Stream<List<dynamic>> getTransaction() async* {
    List _transaction = [];
    final sessionData = await getSession();
    final db = await initDatabase();
    yield* db.createQuery(
        "transactions",
        where: 'action != "delete" AND transaction_quarter = ? ',
        whereArgs: [sessionData['selected_quarter']]
    ).mapToList((row) => TransModel.Transaction.fromMap(row));
  }
2

There are 2 answers

0
Randal Schwartz On

it looks like you have "delete" in your SQL. I think you'll need 'delete'. They are definitely not the same.

0
Oleg Plotnikov On

You can try to pass "delete" in args

db.createQuery(
        "transactions",
        where: 'action != ? AND transaction_quarter = ? ',
        whereArgs: ["delete", sessionData['selected_quarter']]
    )