Home > Software engineering >  multiple arguments in sqflite flutter
multiple arguments in sqflite flutter

Time:02-11

I want to search database based on the keyword. if it title or content contains the keyword then return the data. but it send backs nothing.


  static Future<List<Note>> searchDocuments(String? keyword) async {
    final database = await DatabaseHelper.database();
 
    List<Map<String, dynamic>> allDocuments = await database.rawQuery(
        'SELECT * FROM docs WHERE title=? and content=?',
        ['$keyword%', '$keyword%']);


checked - doesn't work.

CodePudding user response:

  await database.rawQuery(
        'SELECT * FROM docs WHERE title=$keyword AND content=$keyword');

CodePudding user response:

This works.

await database.rawQuery(
        'SELECT * FROM docs WHERE title LIKE ? OR content LIKE ?',
        ['%$keyword%', '%$keyword%']);

  • Related