storesafe / cordova-sqlite-storage-help

Help forum for Cordova sqlite plugin projects
2 stars 1 forks source link

Move from std api to sqlite #18

Closed luigi37 closed 7 years ago

luigi37 commented 7 years ago

Hi. Is it possible to open with this plugin a dB on Android cordova already created with native method?

brodycj commented 7 years ago

If you create a database on Android using the standard android.database API you can open the database using the Cordova plugin. But you have to watch for possible "Multiple SQLite problem" documented in litehelpers/Cordova-sqlite-storage#626 (with a few edits):

From http://ericsink.com/entries/sqlite_android_n.html: in case someone uses android.database.sqlite from another plugin or application-specific Java code to access the same database as this plugin at the same time there is potential for database corruption ref:

Note that the first part about "SQLite and Android N" is NOT a problem with this plugin since it uses its own build of SQLite.

In case anyone encounters this issue the workaround is to open the database with the androidDatabaseImplementation: 2 and possibly androidLockWorkaround: 1 settings as documented.

luigi37 commented 7 years ago

Thanks Chris. So I need just to be carefully about concurrent calls, right? Only my app is accessing this db so I assume that I can swap flawless to the plugin as long as I'm sure no other call is made by std API. Thanks for confirming

brodycj commented 7 years ago

So I need just to be carefully about concurrent calls, right?

Yes. To be on the safe side I recommend that you avoid having the database open in only both the plugin and your code using the std API.

Note that this would NOT be an issue if you use androidDatabaseImplementation: 2, possibly with the androidLockWorkaround: 1 setting as documented.

luigi37 commented 7 years ago

Thank you Chris. I will put those parameters in and test. Very last point... will this plugin work even in the (hopefully unlikely) event that Android and iOS drop websql support? Thanks Luigi

brodycj commented 7 years ago

Very last point... will this plugin work even in the (hopefully unlikely) event that Android and iOS drop websql support?

Absolutely and this is definitely an advantage of using the plugin.

Another tip is that in case you make in app in Cordova then decide to rewrite it as a native app you can continue to use the same database. This should also work if you decide to switch to React Native as well.

luigi37 commented 7 years ago

That's absolutely OUTSTANDING! Thanks a lot Chris! Luigi