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 error with multiple tables in one database (IndexedDB is used, not WebSQL) #51

Closed sascha-gruesshaber closed 9 years ago

sascha-gruesshaber commented 9 years ago

Hei there,

i got a problem on iOS in Safari if I create on startup a Storage with more then one table. The error I get is the following:

"DOM IDBDatabase Expception 8: An operation failed because the requested database object could not be found."

This only appaers if you open the Website in Safari direct and not as an Homescreen-App. I think apps from the homescreen run in a different state and dont support indexddb already.

To recreate this error take your ToDo-List Example App and add a second table into your database and run the app.

var schema = {
  stores:[
  {
    name:'todo',
    keyPath:"timeStamp"
  },
  {
    name:'todo2',
    keyPath:"timeStamp"
  }
  ]
};

After some research i discoverd that on iOS 8 we use indexeddb, not like on iOS 7 WebSQL. Since your own code suggets to not use indexedDB on Safari (cause of their bugs), it looks like the following code returns true, and not false for iOS devices:

/**
 * @final
 * @return {boolean} return indexedDB support on run time.
 */
ydn.db.con.IndexedDb.isSupported = function() {
  if (!ydn.db.base.indexedDb) {
    return false;
  }
  if (goog.userAgent.product.SAFARI)
  {
    // IndexedDB in Safari is too buggy at this moment.
    return false;
  }
  return !!ydn.db.base.indexedDb;
};

To fix the problem, I only changed the above code to:

/**
 * @final
 * @return {boolean} return indexedDB support on run time.
 */
ydn.db.con.IndexedDb.isSupported = function() {
  if (!ydn.db.base.indexedDb) {
    return false;
  }
  if (goog.userAgent.product.SAFARI || goog.labs.userAgent.browser.matchIosWebview_)
  {
    // IndexedDB in Safari is too buggy at this moment.
    return false;
  }
  return !!ydn.db.base.indexedDb;
};

Now on iOS we use WebSQL again and all Works like before. I hope this is detailed enought to describe the Problem and the ongoing fix.

Greets Sascha.

PS: Thanks for this nice Wrapper for Databases!

yathit commented 9 years ago

Hi, thanks for report. It is a known bug #20 #23 Anyways, if you are using latest version, you should not need checking. websql will be selected on Safari browser.

There is a check something like you suggested.