react-native-sqlite-storage

how to use LIKE in query of react-native-sqlite-storage


I want to get every user with name contains "Angel". This is my code

this.DATABASE.transaction(tx => {
  tx.executeSql(
    "SELECT * FROM tblUser WHERE Name LIKE '%?%'",["Angel"],
    (tx, data) => {
      var result = [];
      for (let i = 0; i < data.rows.length; i++) {
        result.push(data.rows.item(i));
      }
    },
})

But I got error "Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters." It just knows ? when it stands alone, not understand as in my query. Is there any solution for this issue?


Solution

  • use

    "SELECT * FROM tblUser WHERE Name LIKE ?",[`%${Angel}%`]