0

我从 YDN-DB 开始时遇到问题。我是说。我设置了一个方案,我初始化了数据库,但是在实例化时会抛出一个错误,上面写着“ConstraintError:DOM Exception IDBDatabase 0”。在事件处理程序中“失败”给了我“版本更改事务在需要升级的事件处理程序中中止。”。阅读我在此链接中发现的问题。找不到分配事件以触发“onupgradeneeded”的方法,我认为这可以解决问题

我留下我的一段代码:

var shopgroups_schema = {
    name: 'shopgroups',
    keyPath: 'id_shop_group',
    autoIncrement: true,
    indexes: [
        {keyPath: 'id_shop_group'},
        {keyPath: 'name'},
        {keyPath: 'share_customer'},
        {keyPath: 'share_order'},
        {keyPath: 'share_stock'},
        {keyPath: 'active'},
        {keyPath: 'deleted'},
        {keyPath: 'date_add'},
        {keyPath: 'date_upd'},
        {keyPath: 'date_upd'}
    ]
};

var shops_schema = {
    name: 'shops',
    keyPath: 'id_shop',
    autoIncrement: true,
    indexes: [
        {keyPath: 'id_shop'},
        {keyPath: 'id_shop_group'},
        {keyPath: 'name'},
        {keyPath: 'id_category'},
        {keyPath: 'id_theme'},
        {keyPath: 'active'},
        {keyPath: 'deleted'},
        {keyPath: 'date_add'},
        {keyPath: 'date_upd'}
    ]
};

var schema = {
    stores: [shopgroups_schema, shops_schema]
};

var schemaName = 'chollingApp4';

var db = new ydn.db.Storage(schemaName, schema);

db.addEventListener('error', function (event) {
  var e = event.getError(); 
  // common errors are AbortError, ConstraintError and UnknownError (possibliy for Quota exceed error).
  // log error for debugging
  console.log('connection failed with ' + e.name);
});

db.addEventListener('fail', function (event) {
  var err = event.getError();
  console.log(event);
  console.log(err);
  console.log('connection failed with ' + err.name + ' by ' + err.message);
  db = null; // no operation can be placed to the database instance
});

db.addEventListener('ready', function (event) {
  var is_updated = event.getVersion() != event.getOldVersion();
  if (is_updated) {
    console.log('database connected with new schema');
  } else if (isNaN(event.getOldVersion()))  {
    console.log('new database created');
  } else {
    console.log('existing database connected');
  }
  // heavy database operations should start from this.
});
4

1 回答 1

2

ConstraintError在数据库打开中表明架构可能是一个问题。我发现你有索引 keyPath,date_upd重复。

于 2013-08-25T02:51:09.953 回答