I'm trying to connect pre-populated sqlite db file to my react-native app. I'm using separate database connect file. File name is 'Database.js'. My .sqlite file location is
android\app\src\main\assets\data
This is src\db\Database.js file
var React = require('react-native');
var SQLite = require('react-native-sqlite-storage')
var db = SQLite.openDatabase({name : 'oneManagerDB', createFromLocation : '~data/oneManager.sqlite'});
export default DBController =
{
_connection:db,
}
And use it other places.
Example of use login.js. file in root of project filder
import DBController from './src/db/Database';
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
loading: false,
};
}
_startSession(){
DBController._connection.transaction(function(tx) {
console.log('stat se');
tx.executeSql(
'UPDATE session SET value=? WHERE param=?',
[
this.state.email,
'user-name'
],
(tx, results) => {
console.log('Results', results.rowsAffected);
console.log('value', this.state.email);
}
);
});
}
...
...
}
Following error show in console with running app on android virtual Device
2019-11-23 11:48:04.883 20947-27177/com.awesomeproject I/ReactNativeJS: OPEN database: oneManagerDB
2019-11-23 11:48:04.888 20947-27182/com.awesomeproject E/unknown:SQLitePlugin: pre-populated DB asset NOT FOUND in app bundle www subdirectory: data/oneManager.sqlite
2019-11-23 11:48:04.888 20947-27182/com.awesomeproject E/unknown:SQLitePlugin: Unable to import pre-populated db asset
2019-11-23 11:48:04.889 20947-27182/com.awesomeproject E/unknown:SQLitePlugin: Unexpected error opening database, stopping db thread
java.lang.Exception: Unable to import pre-populated db asset
at org.pgsqlite.SQLitePlugin.openDatabase(SQLitePlugin.java:395)
at org.pgsqlite.SQLitePlugin.access$000(SQLitePlugin.java:49)
at org.pgsqlite.SQLitePlugin$DBRunner.run(SQLitePlugin.java:904)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Please help me to resolve this