yathit / ydn-db

Javascript database module for Indexeddb, Web SQL and localStorage storage mechanisms supporting version migration, advanced query, SQL and transaction.
Apache License 2.0
503 stars 41 forks source link

iOS 8.4 put only works the second time #76

Open gabrielmaldi opened 9 years ago

gabrielmaldi commented 9 years ago

Hi, thanks for this awesome library. I was just playing around with it and found two very related issues:

With this simple code:

var db = new ydn.db.Storage("TestDatabase", {
    version: 1,
    stores: [{
        name: "TestTable",
        keyPath: "myId",
        autoIncrement: false
    }]
});
db.onReady(function (e) {
    if (e) {
        console.log(e);
        throw e;
    }

    db.get("TestTable", 12345).then(function (record) {
        if (record) {
            console.log("Record found:");
            console.log(record);
        } else {
            console.log("Record not found, adding it...");

            db.put("TestTable", {
                myId: 12345,
                myName: "Foo"
            }).then(function (r) {
                console.log("Record added:");
                console.log(r);
            });
        }
    });
});

The put call only works the second time I run the app on an iPhone with iOS 8.4 (the code runs inside a UIWebView). This is the output:

First run
"Record not found, adding it..."
"Record added:"
12345
Second run
"Record not found, adding it..."
"Record added:"
12345
Third run
"Record found:"
{"myId":12345,"myName":"Foo"}

The same code inside a UIWebView on iOS 7.1 works just fine:

First run
"Record not found, adding it..."
"Record added:"
12345
Second run
"Record found:"
{"myId":12345,"myName":"Foo"}

So that's the first issue I wanted to report.

I then went ahead and created a Plunker to be able to try the code in iOS Safari (instead of the UIWebView): http://embed.plnkr.co/ldYHBaXhkyrMw9ksSYqj/preview

Note that the code in that Plunker contains:

mechanisms: ["websql"]

These are the different scenarios:

mechanisms doesn't make a difference in UIWebView: even with it we need two calls to put.

I'm using YDN-DB I got from this page, more specifically from here.

Thanks!

yathit commented 9 years ago

Could you try using this raw file https://storage.cloud.google.com/ydn-db-d1/1.3.2/ydn.db-isw-core-e-cur-qry-dev-raw.js ?

Thanks for the report.

gabrielmaldi commented 9 years ago

With that raw file the result is the same: on an iOS 8.4 UIWebView I have to run the app twice for the record to be added.

yathit commented 9 years ago

iOS 8.4 UIWebView I have to run the app twice

Can you figure out why?

chaserstrong commented 7 years ago

I have faced the same issue when i ran my web app on ios10.0.2 . After second time ,it shows like that :

unable to open database (14 unable to open database file) connect — ydn.db-is-core-qry.js:5773:90 Od — ydn.db-is-core-qry.js:2005:98 o — ydn.db-is-core-qry.js:1974 T — ydn.db-is-core-qry.js:1949 Je — ydn.db-is-core-qry.js:3532 X — ydn.db-is-core-qry.js:3591 Sf — ydn.db-is-core-qry.js:6008 openDB — service.js:198 queryLastUpdateAt — service.js:59 syncReport — service.js:539 (匿名函数) — login.js:38 n — angular.min.js:2828 $eval — angular.min.js:3864 $digest — angular.min.js:3798 $apply — angular.min.js:3892 (匿名函数) — angular.min.js:2836

And i use the same js plugin mentioned above. Have you ever solved this issue? @yathit