andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.75k stars 521 forks source link

Can not open database in android #514

Open lytrunghieu opened 2 years ago

lytrunghieu commented 2 years ago

I try to open database with database is located in internal storage on Android. But got error "Could not open database"

my code : const db = await SQLite.openDatabase({name : "app_update", createFromLocation : "/storage/emulated/0/app_update.sqlite"});

error log:

openDatabase {"assetFilename": "/storage/emulated/0/app_update.sqlite", "createFromLocation": "/storage/emulated/0/app_update.sqlite", "dblocation": "nosync", "name": "app_update"} [[Error: Could not open database]]

my package.json:

{
  "name": "awesomeproject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.67.4",
    "react-native-sqlite-storage": "^6.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}
iphonic commented 2 years ago

Try this

const db = SQLite.openDatabase({name:'app_update',createFromLocation:'~ app_update.sqlite',location:'default'}, openCB, errorCB);

lytrunghieu commented 2 years ago

Hi @iphonic

Try this

const db = SQLite.openDatabase({name:'app_update',createFromLocation:'~ app_update.sqlite',location:'default'}, openCB, errorCB);

I have try it, but it only open database from local app, can not open database from external storage, example: from Download folder in Android

oukin8023 commented 2 years ago

it

me too

BillDelvin commented 1 year ago

Hi there, I facing the same issue, is there any way to fix it ? and the error in log said "Could not open database"

diazbeltran commented 1 year ago

import RNFetchBlob from 'rn-fetch-blob';

creo que le falta importar el archivo desde el proyecto al dispositivo antes de abrir la DB.