我正在尝试使用 setVersion 让以下代码在 chrom 上工作(因为 onupgradeneeded 尚不可用)。
IDBVersionChangeRequest 填充了 IDBDatabaseException。并且无法调用 onsuccess 函数。我需要在 onsuccess 函数中创建一个 ObjectStore。
特别是这一行:request = browserDatabase._db.setVersion(browserDatabase._dbVersion.toString());
下面是我的代码。任何帮助将不胜感激...
browserDatabase._db = null;
browserDatabase._dbVersion = 4;
browserDatabase._dbName = "mediaStorageDB";
browserDatabase._storeName = "myStore";
var request = indexedDB.open(browserDatabase._dbName);
// database exist
request.onsuccess = function(e)
{
browserDatabase._db = e.target.result;
// this is specifically for chrome, because it does not support onupgradeneeded
if (browserDatabase._dbVersion != browserDatabase._db.version)
{
request = browserDatabase._db.setVersion(browserDatabase._dbVersion.toString());
request.onerror = function(e) { alert("error") };
request.onblocked = function(e)
{
b = 11; // for some reason the code goes here...
}
request.onsuccess = function(e)
{
browserDatabase._db.createObjectStore(browserDatabase._storeName, {autoIncrement: true});
}
}
}