我试图在我的索引数据库中插入数据,但永远不会调用函数 onupgradeneed,只是调用成功。数据库的版本总是相同的(它是一个全局变量)。我知道为了进入 onupgradeneed 版本必须始终相同。就我而言,就是这样。所以,我没有数据......我该怎么办?谢谢!
var db;
var dbname = "mi";
var dbversion = 1;
function abrirDB()
{
if (plataforma == plataformaW8) {
if (db == null) {
var request = window.indexedDB.open(dbname, dbversion);
request.onsuccess = function (evt) {
db = evt.target.result;
if (db.objectStoreNames.length == 0)
crearDB();
};
}
}
}
function crearDB() {
//Declaración datos BBDD
var paisesData = [{ id_pais: 1, pais: "Arabia Saudí", continente: "Asia", capital: "Riad", paisurl: "arabiasaudi", continenteurl: "asia" },
{ id_pais: 2, pais: "Emiratos Árabes Unidos", continente: "Asia", capital: "Abu Dhabi", paisurl: "emiratosarabes", continenteurl: "asia" }];
//////////
//Abrir BBDD
var request =window.indexedDB.open(dbname, dbversion);
request.onerror = function (evt) {
console.log("Error al abrir la bbdd" + evt.target.errorCode);
};
request.onupgradeneeded = function (evt) {
db = evt.target.result;
var storePaises = db.createObjectStore(storePaisesNombre, { keyPath: "id_pais", autoincrement: false, unique: true });
.......
request.onsuccess = function (evt) {
//db = request.result;
db = evt.target.result;
};
}