使用IndexedDB创建多个对象库时,Safari 7.1中的UnknownError

时间:2014-11-13 00:04:46

标签: javascript safari indexeddb

我想进行健全性检查,看看是否有其他人遇到Safari 7.1和IndexedDB的问题。似乎我收到类型为UnknownError的错误,根据http://www.w3.org/TR/IndexedDB/的规范,当"由于与数据库本身无关且未被任何其他错误覆盖的原因而失败时,操作失败。"这是在第一次调用此函数后,在第一次调用调用回调(onSuccess或onError)之后发生的。这是我创建对象存储的功能,可以在Chrome和Firefox中使用。

IndexedDBClient.prototype.createObjectStore = function(options) {
  if (this.checkIfObjectStoreExists(options.objectStoreName)) {
    options.onError(this.objectStoreDNEMessage);
    return;
  }

  var objectStore;

  var objectStoreCreated = false;
  var databaseOpened = false;

  var version = this.database.version;
  var dbName = this.database.name;
  this.database.close();
  var request = indexedDB.open(dbName, ++version);
  var that = this;

  request.onupgradeneeded = function(e) {
    that.database = e.target.result;
    objectStore = that.database.createObjectStore(options.objectStoreName, { keyPath: options.keyPathName });

    objectStore.transaction.oncomplete = function(e) {
      objectStoreCreated = true;
      successCallback();
    }

    objectStore.transaction.onerror = function(e) {
      options.onError(e);
    };
  };

  request.onsuccess = function(e) {
    databaseOpened = true;
    successCallback();
  }

  request.onerror = function(e) {
    options.onError(e);
  };

  request.onblocked = function(e) {
    typeof options.onBlocked === 'function' && options.onBlocked();
  };

  function successCallback() {
    // This is needed because we must be sure that both the objectstore creation transaction has completed,
    // and the db open request has fired the onsuccess event.
    objectStoreCreated && databaseOpened && options.onSuccess(objectStore);
  }
};

1 个答案:

答案 0 :(得分:1)

Safari浏览器中的IndexedDB API在多个商店交易中有bug