3

I am having a problem with putting a document to the local database.

The code I use is as follows:

var localDB = new PouchDB("db_local", {auto_compaction: true});
localDB.put(poi, function callback(err) {
  if (!err) {
    if (networkState == Connection.NONE || navigator.onLine == false)
      navigator.notification.alert(i18n.t("messages.contributionSuccessNoInternet"), contributionSuccess, "Land Cover Collector", i18n.t("messages.ok"));
    else
      navigator.notification.alert(i18n.t("messages.contributionSuccess"), contributionSuccess, "Land Cover Collector", i18n.t("messages.ok"));
  }
  else {
    navigator.notification.alert(i18n.t("messages.errorStorage"), null, "Land Cover Collector", i18n.t("messages.ok"));

    remotePointsDB.put(poi, function callback(err) {
      if (!err)
        navigator.notification.alert(i18n.t("messages.contributionSuccess"), contributionSuccess, "Land Cover Collector", i18n.t("messages.ok"));
      else
        navigator.notification.alert(i18n.t("messages.error") + " " + err, null, "Land Cover Collector", i18n.t("messages.ok"));
    });
  }
});

Strangely not of the alerts are happening, and this happens on only one device I have. I am using Chrome browser, and compiling the code for Android with Cordova. The device has few free storage. Can anyone guess what can be the reason?

EDIT:

localDB.put(poi, function callback(err, response) {
  if (!err) 
    alert("local success");
  else 
    alert("local: " + err);
});

remotePointsDB.put(poi, function callback(err, response) {
  if (!err)
    alert("remote success");
  else
    alert("remote: " + err);
});
Eylül
  • 139
  • 1
  • 3
  • 13
  • Are any lines of the callback being hit? Are `navigator.notification.alert` and `i18n.t` generally working outside this callback? – Will Jun 06 '18 at 16:51
  • @WillCain yes, those work. To make sure that local PouchDB doesn't work, I edited the code as in my answer. In this case I get "remote success", but nothing else. Looks like local put is completely ignored. As I said before, this happens on only one Android device (tested on 3 other Android devices, iPad, one Linux desktop). – Eylül Jun 07 '18 at 11:58
  • Have you enabled debug mode to see what it says? `PouchDB.debug.enable('*');`. – Henrik Andersson Jun 07 '18 at 12:00
  • The lack of an error message is frustrating; sounds like a bug in the device or pouchdb or the interaction. https://pouchdb.com/errors.html But browser storage limits vary greatly by browser and OS; there is no standard. https://stackoverflow.com/questions/2989284/what-is-the-max-size-of-localstorage-values – Will Jun 07 '18 at 12:48
  • @HenrikAndersson I tried now. I see: pouchdb:api db_local +3m put pouchdb:api +12ms put pouchdb:http GET +4ms pouchdb:http PUT +211ms / pouchdb:api +7s put success {ok: true, id: "x", rev: "1_x"} – Eylül Jun 07 '18 at 12:49
  • GET is similar to PUT. Even empty local storage cannot be retrieved. This is what I see on the console: pouchdb:api db_local +30s allDocs {include_docs: true} pouchdb:api +2m allDocs {include_docs: true} pouchdb:http GET +4ms /_all_docs?include_docs=true pouchdb:api +1s allDocs success {total_rows: 65, offset:0, rows: Array(65)} It looks like, both for PUT and GET neither success or error returns for local. – Eylül Jun 07 '18 at 13:09
  • @WillCain thank you! https://pouchdb.com/faq.html says that on Chrome that I am testing IndexedDB is used, which is likely to have more storage. In any case, I should get an error to handle the case. – Eylül Jun 07 '18 at 13:45

0 Answers0