Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database lost on app update #61

Open
Turv opened this issue May 23, 2017 · 5 comments
Open

Database lost on app update #61

Turv opened this issue May 23, 2017 · 5 comments

Comments

@Turv
Copy link

Turv commented May 23, 2017

Hi,

I have an Android/IOS Ionic (cordova) app, the initial database when created is seeded from a list of SQL Queries. I then store various presets, settings, and stats in this database once created.

When an update is released to the app store and the app is updated, the SQL Database is completely lost so I lose any settings, and stats that had already been created, as the database is effectively overwritten.

I create the database using the following call, as I'm storing the database in a central location (Library) I'd expect the database to still exist on an app update and thus never be lost. Can you advise if I am creating the database correctly, and that I am correct in presuming I should be able to have a persistent database with app updates?

_db = window.sqlitePlugin.openDatabase({ name: "app.db", iosDatabaseLocation: 'Library', location: 'default', createFromLocation: 1 });

@brodycj
Copy link
Owner

brodycj commented May 23, 2017

You are using both location and iosDatabaseLocation which is wrong. As already documented you have to use one or the other.

@Turv
Copy link
Author

Turv commented May 23, 2017

Hi @brodybits

As this is a cross platform app, with the same codebase being used for both Android and iOS. Please can you tell me how I would handle having a persistent database on both platforms?

I wouldn't want to strictly only use iosDatabaseLocation if that's not going to work on Android, or are you suggesting that instead we need to have a different openDatabase call per platform? I.e.

if (ionic.Platform.isIOS())
    _db = window.sqlitePlugin.openDatabase({ name: "app.db", iosDatabaseLocation: 'Library', createFromLocation: 1 });
else 
    _db = window.sqlitePlugin.openDatabase({ name: "app.db", location: 'default', createFromLocation: 1 });

If the above is the case, can you advise if location: 1 (integer) is actually the correct option for Android too, to be in a shared location for a persistent database?

Thanks

@brodycj
Copy link
Owner

brodycj commented May 23, 2017

On Android and Windows the plugin always stores the database in the same place. The iosDatabaseLocation setting makes it clear that you change the database location on iOS only.

@Turv
Copy link
Author

Turv commented May 23, 2017

@brodybits

Thanks for both your quick responses. In which case I will change my openDatabase command to just use the iosDatabaseLocation _db = window.sqlitePlugin.openDatabase({ name: "app.db", iosDatabaseLocation: 'Library', createFromLocation: 1 });

If there is no way to change the location on Android, do you happen to know by default where this is stored, and if an app update may cause a similar overwrite of the database (I.e. I instead need to change the infrastructure of the app to sync the data with the web opposed to a local database).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants