Reputation: 6521
I'm trying to use https://github.com/andpor/react-native-sqlite-storage for SQLite.
I made a sqlite database and it is pre-populated.
On my react-native project, I put players.db
file to /www
folder as documentation says.
But when I inspect from console opening database is failing. I can not open my pre-populated sqlite database.
I tried these options and all of them not working for me;
var db = SQLite.openDatabase({name : "players.db", createFromLocation : "~players.db"});
var db = SQLite.openDatabase({name : "players.db", createFromLocation :1});
var db = SQLite.openDatabase({name : "players", createFromLocation : "~players.db"});
And console output is:
OPEN database: players
Running application "SampleApp" with appParams: {"rootTag":31}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
new transaction is waiting for open operation
OPEN database: players failed, aborting any pending transactions
Upvotes: 5
Views: 7891
Reputation: 197
For me it worked after I put my sqlite db file in this directory:
/android/app/src/main/assets/www
Upvotes: 0
Reputation: 6521
Finally I found the answer.
ProjectFolder/android/app/src/main/assets
directory is same to /www folder. So don't put your database file to /www
. Put it to /android/app/src/main/assets
folder.
Then you can use it like
var db = SQLite.openDatabase({name : "players.db", createFromLocation : "~players.db"});
Upvotes: 13
Reputation: 60
In Android, place your database file in 'PROJECT\android\app\src\main\assets' directory. If your database filename is different (say, players.db VS example.db) then,
var db = SQLite.openDatabase({name : "players.db", createFromLocation : "~example.db", location: 'Library'});
If your filename is same as the database (both named players.db) then
var db = SQLite.openDatabase({name : "players.db", createFromLocation : "~players.db", location: 'Library'});
If you have already messed up with importing a pre-populated database, try clearing up the application data from the emulator/mobile phone and/or uninstalling the app completely before following the steps above.
Upvotes: 4
Reputation: 1447
If you are using defaults then, try:
var db = SQLite.openDatabase({name : "players.db"});
this should work.
Upvotes: -1