Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

399
Views
Error opening database in expo - sqlite (react native)

I wanted to know if you could help me with the following error:

I'm trying to remove the EXPO SQLite base in React-Native and then import another base that I have in my folder.

When I do, it throws me the following error:

Error: no such table: users (code 1 SQLITE_ERROR): , while compiling:

this is my code:

import React, { useState, useEffect } from 'react';
const SQLite = require('expo-sqlite')
import * as FileSystem from 'expo-file-system';
import { Asset } from "expo-asset";
var db = null;
export default class SQLiteScreen extends React.Component {
    constructor() {
        super();
    }

    /*async openDatabase() {
        if (!(await FileSystem.getInfoAsync(FileSystem.documentDirectory + 'SQLite')).exists) {
          await FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'SQLite');
        }
        await FileSystem.downloadAsync(
          Asset.fromModule(require('./MainDB.db')).uri,
          FileSystem.documentDirectory + 'SQLite/MainDB.db'
        );
        db = await SQLite.openDatabase(`MainDB.db`);
    }
    */
    async openDatabaseIShipWithApp() {
 
        if (!(await FileSystem.getInfoAsync(`${FileSystem.documentDirectory}SQLite/MainDB.sqlite`)).exists) {
            await FileSystem.makeDirectoryAsync(`${FileSystem.documentDirectory}SQLite/`, { intermediates: true });
           const asset = await Asset.fromModule(require("./MainDB.db"));
           await FileSystem.downloadAsync(asset.uri, `${FileSystem.documentDirectory}SQLite/MainDB.sqlite`);      
        }
        db = await SQLite.openDatabase(`MainDB.sqlite`);
    }

    async deleteDatabaseWithApp(){
        const internalDbName =  "MainDB.sqlite"; // Call whatever you want
        const sqlDir =  FileSystem.documentDirectory + "SQLite/";
        if ((await FileSystem.getInfoAsync(sqlDir + internalDbName)).exists){
             await FileSystem.deleteAsync(sqlDir+internalDbName,
            {idempotent:true})
        }
    }


    ExecuteQuery = (sql, params = []) => new Promise(async (resolve, reject) => {
        await this.openDatabaseIShipWithApp();
        db.exec([{ sql: 'PRAGMA foreign_keys = ON ; ', args: [] }], false, () => { });
        db.transaction((trans) => {
            trans.executeSql(sql, params, (trans, results) => {
                resolve(results);
            },
                (_, error) => {
                    reject(error);
                });
        });
    });

}

I call the function as follows:

let query = `SELECT * FROM personal`;
await new SQLiteScreen().deleteDatabaseWithApp();
let selectQuery = await new SQLiteScreen().ExecuteQuery(query);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!