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

Android not saving the inserts [workaround needed] #193

Closed
chintanop opened this issue Mar 1, 2015 · 37 comments
Closed

Android not saving the inserts [workaround needed] #193

chintanop opened this issue Mar 1, 2015 · 37 comments

Comments

@chintanop
Copy link

@brodybits Seems like a bunch of folks are facing this issue: on Android: https://groups.google.com/forum/#!topic/Cordova-SQLitePlugin/oq8wMDSH4M4

Cordova: 3.5.0
Android API Level: 19

Any idea?

@brodycj
Copy link
Contributor

brodycj commented Mar 1, 2015

It sounds like an issue introduced by recent updates to the Android sqlite classes. SQLite itself should never do this: https://www.sqlite.org/transactional.html

@brodycj
Copy link
Contributor

brodycj commented Mar 1, 2015

From December 2014:

On Tue, Dec 16, 2014 at 1:48 PM, [email protected] wrote:

I have been using this plugin for some time now, and recently i noticed that
sometimes plugin just doesn't insert anything in database. From the several
things that need to be initialized on app start, nothing is inserted, and of
course my whole app breaks.
I noticed this after updates to android support jar, cordova and few other
things.
I can't think of any reason why something like this would occur so please
any tips would be helpful.
Thank you

On Wed, Dec 17, 2014 at 1:59 PM, [email protected] wrote:

After hours of trying to figure out why/when does db fails i finally figured
it out.
When i start the app then exit it (not close/swipe it) and return back to
app sqlite plugin notifies me again in console that database is opened
again

SQLitePlugin openargs: {"name":"insideoutdb","bgType":1}
I am using cordova 4.0.0, Ionic 1.2.8 and sqlite 3.8.6 on lollipop and
kitkat.
My understanding is that database isn't closed until you explicitly close
the app ( or android kills it ) so when i come back to my app it tries to
open already opened db and it overwrites it or crash.

From February 2015:

On Sun, Feb 15, 2015 at 12:48 AM, Cesar Fernandes [email protected] wrote:

I have the same problem.... I am working with latest versions of cordova
and plugin...

I manage 3 sqlite tables. I make some inserts in one of the tables, and when
i close the app and come back, the inserts get lost... then for some reason
that i can not find out, i populate the second table with lots of entries
from one web service, and this one does not get lost.... i already tried
lots of things to solve this problem, but i am almost givin up...

I alway get messages that database is locked , or database was closed bu
remained 1 without closing....

On Sun, Mar 1, 2015 at 1:54 AM, COP [email protected] wrote:

Hi, I'm also having the same problem on Android

The inserts work fine till the APP is on, i.e. you can insert and select the
data.

Once, you KILL the app. All the inserts are gone! Works fine in iOS - the
Android is not working.

@brodycj
Copy link
Contributor

brodycj commented Mar 1, 2015

What I am suspecting now is the following commit in the Android database classes: aosp-mirror/platform_external_sqlite@d4f30d0

It references the following sqlite fossil commit: http://www.sqlite.org/src/info/6c4c2b7dba

@brodycj
Copy link
Contributor

brodycj commented Mar 1, 2015

I made a possible workaround in the branch xb-android-lock-workaround. Can you please let us know if this will solve the problem?

@chintanop
Copy link
Author

@brodybits Thanks a lot for quick turn-around! this worked!

@brodycj
Copy link
Contributor

brodycj commented Mar 2, 2015

Happy that it solves your problem. But it points to an issue with the Android sqlite library. My idea is to make this workaround an option for those who need it.

@brodycj brodycj reopened this Mar 2, 2015
brodycj pushed a commit that referenced this issue Mar 9, 2015
…bject

(preparation for workaround for Android db locking/closing issue [see #193])

Replace tabs with spaces
brodycj pushed a commit that referenced this issue Mar 10, 2015
Fixes:
- #193: workaround for Android db locking/closing issue
- #144: convert array parameters to string to match Web SQL
- #199: fix double-precision REAL values in result for iOS version
- #150/#153: close Android db before removing from map
- Fix truncation in iOS query result in case of UNICODE NULL (\0 or \u0000) (ref: PR #170)
- Some fixes for error handling to be consistent with Web SQL (ref: PR #170)

Testing ONLY:
- #147: testing with UNICODE line separator
- #195: Reproduce issue with double-precision REAL number on WP(8) ONLY
brodycj pushed a commit that referenced this issue Mar 10, 2015
Fixes:
- #193: workaround for Android db locking/closing issue
- #144: convert array parameters to string to match Web SQL
- #199: fix double-precision REAL values in result for iOS version
- #150/#153: close Android db before removing from map
- Fix truncation in iOS query result in case of UNICODE NULL (\0 or \u0000) (ref: PR #170)
- Some fixes for error handling to be consistent with Web SQL (ref: PR #170)

Testing ONLY:
- #147: testing with UNICODE line separator
- #195: Reproduce issue with double-precision REAL number on WP(8) ONLY
@brodycj
Copy link
Contributor

brodycj commented Mar 10, 2015

The workaround as proposed was validated by @chintanop and is now optional, as described in README.md.

@brodycj brodycj closed this as completed Mar 10, 2015
brodycj pushed a commit that referenced this issue Mar 10, 2015
Related to the following fixes:
- #193: workaround for Android db locking/closing issue
- #144: convert array parameters to string to match Web SQL
- #199: fix double-precision REAL values in result for iOS version
- #150/#153: close Android db before removing from map
- Fix truncation in iOS query result in case of UNICODE NULL (\0 or \u0000) (ref: PR #170)
- Some fixes for error handling to be consistent with Web SQL (ref: PR #170)
brodycj pushed a commit that referenced this issue Mar 18, 2015
@cesar1983
Copy link

What files should I overwrite from the workaround branch? I replaced only SQLitePlugin.java and SQLitePlugin.js , but seems to be still wrong

@brodycj
Copy link
Contributor

brodycj commented Mar 20, 2015

The workaround branch is no longer supported. Please completely remove your app from the Android simulator or device, install the latest update from the master branch of this plugin, and use the androidLockWorkaround option in sqlitePlugin.openDatabase, as described in the readme.

@brodycj brodycj reopened this Mar 20, 2015
@cesar1983
Copy link

Ok! thank you very much! I will play with that now...

@brodycj
Copy link
Contributor

brodycj commented Mar 20, 2015

Also note that this is really a bug in the Android database libraries and not this project. Unfortunately I have not reproduced this issue myself. I have implemented a very crude workaround but this should really be fixed in the Android code itself!

As I said before, I have a theory that the issue was introduced in the following commit in the Android database classes: android/platform_external_sqlite@d4f30d0, which references the following sqlite fossil commit: http://www.sqlite.org/src/info/6c4c2b7dba

It would really help if someone could file a bug on the Android project itself at: https://code.google.com/p/android/issues/list

@cesar1983
Copy link

I really appreciate your help. I will write to Android developers like you
told...

Tks again
Em 20/03/2015 22:19, "Chris Brody" [email protected] escreveu:

Also note that this is really a bug in the Android database libraries and
not this project. Unfortunately I have not reproduced this issue
myself. I have implemented a very crude workaround but this should
really be fixed in the Android code itself!

As I said before, I have a theory that the issue was introduced in the
following commit in the Android database classes:
aosp-mirror/platform_external_sqlite@d4f30d0
aosp-mirror/platform_external_sqlite@d4f30d0,
which references the following sqlite fossil commit:
http://www.sqlite.org/src/info/6c4c2b7dba

It would really help if someone could file a bug on the Android project
itself at: https://code.google.com/p/android/issues/list

Reply to this email directly or view it on GitHub
#193 (comment)
.

@cesar1983
Copy link

Yeah, i think i ll have to write to android developers.. sorry because i
was hopefull.. i have to finish this project soon... :/

I re-installed the plugin it is still not working.. i can see in the catlog
the workaround is being called "Android db closing/locking workaround
applied" ...

I use a moto G android 4.4 ...

When i emulate it in eclipse, it is working , but not on my device.

On Fri, Mar 20, 2015 at 10:18 PM, a Cesar Fernandes [email protected]
wrote:

I really appreciate your help. I will write to Android developers like you
told...

Tks again
Em 20/03/2015 22:19, "Chris Brody" [email protected] escreveu:

Also note that this is really a bug in the Android database libraries and

not this project. Unfortunately I have not reproduced this issue
myself. I have implemented a very crude workaround but this should
really be fixed in the Android code itself!

As I said before, I have a theory that the issue was introduced in the
following commit in the Android database classes:
aosp-mirror/platform_external_sqlite@d4f30d0
aosp-mirror/platform_external_sqlite@d4f30d0,
which references the following sqlite fossil commit:
http://www.sqlite.org/src/info/6c4c2b7dba

It would really help if someone could file a bug on the Android project
itself at: https://code.google.com/p/android/issues/list

Reply to this email directly or view it on GitHub
#193 (comment)
.

Café Hostel
Rua Agissê, 152 - Vl. Madalena
+55 11 2649-7217
http://www.cafehostel.com.br
https://www.facebook.com/cafehostelsp

@brodycj
Copy link
Contributor

brodycj commented Mar 22, 2015

That would really help me.

@brodycj brodycj changed the title Android not saving the inserts Database closing/locking issue in some Android versions [Android not saving the inserts] Mar 23, 2015
@cherrypickercherrypicker

Does this issue occurs only when you use db.transaction or on db.executeSql too?

@brodycj
Copy link
Contributor

brodycj commented Aug 3, 2015

Does this issue occurs only when you use db.transaction or on db.executeSql too?

Unfortunately I have not reproduced this issue myself so far. The workaround is only implemented in the case of using db.transaction().

@mdbw3
Copy link

mdbw3 commented Jun 21, 2016

I'm running into this issue also. Does it also occur when opening the database with androidDatabaseImplementation: 2?

As it occurs occasionally, testing / debugging is quite a challenge.

@brodycj
Copy link
Contributor

brodycj commented Jun 21, 2016

I'm running into this issue also. Does it also occur when opening the database with androidDatabaseImplementation: 2?

As it occurs occasionally, testing / debugging is quite a challenge.

This should only be an issue if you open the database with androidDatabaseImplementation: 2 setting. If you see this issue with the default settings then please raise a new issue along with some details that can help me reproduce the problem.

As documented, there is an androidLockWorkaround that you can use in case you encounter this issue. Please read and follow the documentation very carefully if you need to use this setting.

@mdbw3
Copy link

mdbw3 commented Jun 21, 2016

Ok, thanks. I'll look into it and open a new issue if I can't find a related item or solution.

Edit: the example code at the 'Workaround for Android db locking issue' section is a little bit confusing:
var db = window.sqlitePlugin.openDatabase({name: 'my.db', location: 'default', androidLockWorkaround: 1});

The 'androidDatabaseImplementation: 2 ' setting isn't set, so the example code doesn't make sense, right?

@brodycj
Copy link
Contributor

brodycj commented Aug 4, 2016

The 'androidDatabaseImplementation: 2 ' setting isn't set, so the example code doesn't make sense, right?

@mdbw3 the README.md has been updated, thanks.

@craig-at-rsg
Copy link
Contributor

I'm having this problem, but I don't use androidDatabaseImplementation: 2, and the data is lost without closing the app. Specifically, I insert a row and get back the inserted id, then the next insert to that table gets back the same insert id.

One potential cause is that I'm opening the database read-only in some Android plugin code. My understanding was that read-only wouldn't affect a read-write connection, but maybe that's just for Sqlite itself and not for something that wraps it (Android code or this plugin).

What info would be useful in tracking this down? Or is there already a workaround (can I use androidLockWorkaround: 1 without androidDatabaseImplementation: 2)? The docs seem to say that won't help.

@brodycj
Copy link
Contributor

brodycj commented Dec 22, 2016

Hi @craig-at-rsg,

That really sounds like a different problem. I suggest we discuss this in a new issue. Thanks!

@craig-at-rsg
Copy link
Contributor

@brodybits Thanks for getting back to me so fast. I just opened #601 for this.

@brodycj brodycj changed the title Database closing/locking issue in some Android versions [Android not saving the inserts] Android not saving the inserts [workaround needed] Apr 20, 2017
@dex252
Copy link

dex252 commented Feb 6, 2020

I am writing through a translator. Hello, I will raise this problem again. It occurs when UPDATE records in the database. I would like to use the solution proposed in the documentation in the "Workaround for Android db locking issue" section, but the constructor lacks androidDatabaseProvider and androidLockWorkaround. Are there any other solutions to this problem?
I am sure that the method works without exception and the input data is correct, but in practice nothing happens. After UPDATE it follows: .then, I don’t know what it returns ... I know that catch does not work out. It is strange that this does not happen for all records, and only after the first successful UPDATE record. Other records work fine, but favorites will work until the first change, the second and the next ones no longer work.

@brodycj
Copy link
Contributor

brodycj commented Feb 6, 2020

Please raise a new issue with some information about what is happening, how you open the database, how you store data, and what kind of devices you see the the issue on. I generally do not support discussions in closed issues.

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

7 participants