Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nawazokz opened this issue Mar 12, 2024 · 1 comment
Open

Comments

@nawazokz
Copy link

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

@alihasnain3
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants