Skip to content

Issue with executing FTS5 search query in React Native SQLite #588

@vasanshettiTharun

Description

@vasanshettiTharun

The SELECT query using MATCH should return results that match the search term ('simple') from the FTS5 table. Specifically, the expected behavior is for the results.rows.raw() to contain the expected data from the FTS5 table.

Current Behavior

SELECT content FROM FTS5 WHERE content MATCH 'simple';

does not return the expected results. The log shows the "FTS5 table exists." message, but no results are returned for the search query, even though the data has been inserted correctly.

Im getting inserting error while inserting data programatically even if i insert manually serach is not happening using fts5 but working with fts4 table

this is sample code:
useEffect(() => {
const searchFTS5 = async () => {
try {
const db = await openDatabase();
console.log('working');

    await new Promise((resolve, reject) => {
      db.transaction(tx => {
        tx.executeSql(
          "SELECT name FROM sqlite_master WHERE type='table' AND name='FTS5';",
          [],
          (_, results) => {
            if (results.rows.length === 0) {
              console.error("FTS5 table does not exist.");
            } else {
              console.log("FTS5 table exists.");
            }
          },
          (_, error) => console.error("Error checking FTS5 table:", error.message || error)
        );
      });
      db.transaction(tx => {
        tx.executeSql(
          "INSERT INTO FTS5 (content, id) VALUES (?, ?);",
          ["This is a simple test", 1],
          () => console.log("Sample data inserted."),
          (_, error) => console.error("Insert Error:", error.message || error)
        );
      });
      
      db.transaction(tx => {
        tx.executeSql(
          "SELECT * FROM FTS5;",
          [],
          (_, results) => console.log("FTS5 Table Data:", results.rows.raw()),
          (_, error) => console.error("Error fetching FTS5 data:", error.message || error)
        );
      });
      
      db.transaction(tx => {
        tx.executeSql(
          SELECT content FROM FTS5 WHERE content MATCH 'simple';,
          [],
          (_, results) => console.log('Search Results:', results.rows.raw()),
          (_, error) => console.error('Query Error:', error.message || error)
        );
        
      });
    });
  } catch (error) {
    console.error('Transaction Error:', error.message || error);
  }
};
searchFTS5();

}, []);

Context
This issue affects the ability to perform full-text search queries in the app using SQLite's FTS5 extension, preventing data retrieval based on search terms.

Environment
React Native SQLite Storage Version used: 6.0.1

React Native version used: 0.78

Debug logs:
working
console.js:654 FTS5 table exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions