react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

Cannot get data from the pre-populated sqlite database in react native

Open nawazokz opened this issue 1 year ago • 1 comments

I spend almost 10 hour just to get data from the pre populated database. I place my db file for android in \android\app\src\main\assets i am using react native version 0.73.4

here is my code import SQLite from 'react-native-sqlite-storage'; const initializeDatabase = async () => { try {

  const db = await SQLite.openDatabase({
    name: 'kitabosunnat.db',
    createFromLocation: '~kitabosunnat.db',
  });

  await db.transaction(tx => {
    tx.executeSql(
      'SELECT * FROM Favrouit',
      [],

      (tx, results) => {
        const temp = [];
        const rows = results.rows;
        for (let i = 0; i < rows.length; i++) {
          console.log('Row:', rows.item(i));
          temp.push(rows.item(i));
          // Process and use the data as needed
        }
        setData(temp);
      },
      error => {
        console.error('Error executing SQL query:', error);
      },
    );
  });
} catch (error) {
  console.error('Error initializing database:', error);
}

}; useEffect(() => { initializeDatabase(); console.log(data); }, []); with all the solution i searched on google i still have the following problem

Error executing SQL query {"code": 0, "message": "no such table: categories (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM categories"}

Note: table is present in the database with correct spelling i have tried all the solution but cannot succeed

nawazokz avatar Mar 12 '24 09:03 nawazokz

@nawazokz were you able to find any solution for this issue?

alihasnain3 avatar May 13 '24 19:05 alihasnain3