I want to re-open a closed database without loosing its content.
Current Behavior
I think this is what is happening: Upon reopening, it is creating a new database with the same name of the database I want to re-open, overwriting my original database.
Steps to reproduce
I am creating a database foo with the table bar like this:
import SQLite from 'react-native-sqlite-storage';
SQLite.enablePromise(true);
const database = SQLite.openDatabase(
{
name: 'foo.db',
location: 'Library'
},
console.log('sucessfully created database'),
error => {
console.log('failed to create database', error)
}
);
database.transaction(tx => {
tx.executeSql('CREATE TABLE IF NOT EXISTS bar(....);'
});
I then close this database
database.close();
Later in my App, I want to reopen the database and perform an INSERT. I use the same code I used for creating the database
Expected Behavior
I want to re-open a closed database without loosing its content.
Current Behavior
I think this is what is happening: Upon reopening, it is creating a new database with the same name of the database I want to re-open, overwriting my original database.
Steps to reproduce
I am creating a database
foo
with the tablebar
like this:I then close this database
Later in my App, I want to reopen the database and perform an
INSERT
. I use the same code I used for creating the databaseAnd then I perform the
INSERT
This gives me
and
and
I assume it's recreating the database in my second
openDatabase()
statement, overwriting everything that was there - including the tablebar
.Context
I want to be able to re-open a database that has been created by this library.
Your Environment