Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

400
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda