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

Unique constraint failed error - 2067 with pouchdb-mapreduce- Android #107

Open
SuhailMehta opened this issue Dec 29, 2016 · 9 comments
Open

Comments

@SuhailMehta
Copy link

I am working on react-native project which uses sync so we decided to use couch-pouch. With pouchdb websql adapter i am using your your sqlite storage which is working fine for ios app but when we try to run the same app on android its was able to insert data from couch to sqlite storage but when we query the data it throws an error pointing Unique constraint failed for document-store.id (error - 2067).

With pouchdb-mapreduce i can see the _pouch_dbName-mrview db being created but it was empty.
So, before query the indexes insert must be done for a view but as db is empty i can't under why unique constraints are failing.

Can you suggest the a way to resolve it or i can add some more information to it.

@itinance
Copy link
Contributor

Unique constraint errors have nothing to do with this library, this is SQL related. Check the database schema and especially all unique indexes and primary keys. There should be the root cause of your exception

@SuhailMehta
Copy link
Author

I am understanding what you are saying but the thing is same js wrapper is working fine on ios but only throwing error for android on same data set and same query execution.

@SuhailMehta
Copy link
Author

SuhailMehta commented Dec 29, 2016

i think i got the issue. my id field contains \u000 character which was constructed by pouchdb-mapreduce and thats not supported for cordova-sqlite-storage.
My id(unique) field contains 55323246\u0000\u00004Category_6191\u000031\u0000\u0000.
And data after \u0000 gets truncated some how and every time it tries to insert 55323246 and cause unique constraint failed.
https://stash.mcon-group.com/users/ok250343/repos/pouchdb-hello-world/browse/plugins/cordova-sqlite-storage?at=master

@andpor
Copy link
Owner

andpor commented Jan 18, 2017

@brodybits - Chris hi, is this something that has been identified in the core cordova-storage module and can be fixed?

@craftzdog
Copy link

@SuhailMehta Hi, did you manage it? Seems like pouchdb is heavily using \u0000 for indexing.

@andpor
Copy link
Owner

andpor commented Mar 20, 2017

It seems that '\u000' is wrongfully interpreted as '\0' on some platforms and thus the issue. I have found some mentions of it on the pouchdb website. Perhaps newer versions of PouchDB shy away from using this character?

@craftzdog
Copy link

I think it's react native-related problem: facebook/react-native#12731

@SuhailMehta
Copy link
Author

@noradaiko I have change '\u0000' in pouchdb to '\u0001' in pouchdb internals. I think if you will dig inside sql adapter or if you will read its(sql adapter) read me you have to replace '\u0000' to '\u0001' for some platforms (android platform for me).
Actually code is written to replace the same in pouchdb-adapter-websql-core but it was not working.
So, i change var zero = '\u0001' in pouchdb-collate and everything is working fine for then.

@craftzdog
Copy link

@SuhailMehta Thanks for the answer.
The code replacing '\u0000' in pouchdb-adapter-websql-core works only for blobs(attachments) so it won't fix the problem.
I'm afraid that it corrupts data if I change internal pouchdb.

Instead, I made react-native-sqlite-2 which code base is from Nolan's cordova-plugin-sqlite-2 with my patch for this problem, and it works pretty well on both Android and iOS for now.
Check it out if you are interested in.

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

No branches or pull requests

4 participants