我正在尝试运行这些函数集:
function erorr(e) {
// error getting database
alert(e.message);
}
window.onload = function() {
prepareDatabase(erorr);
};
function prepareDatabase(error) {
return openDatabase('tasks13', '', 'Offline task storage', 3*1024*1024, function (db) {
db.changeVersion('', '1.0', function (t) {
t.executeSql('CREATE TABLE tasks (id, detail,status)');
}, error);
});
}
但是,在运行这个之后,我得到一个错误
current version of the database and 'oldVersion' argument do not match
。不知道我在这里做错了什么。
最佳答案
我也遇到了同样的错误。
我避免使用db.changeVersion,而是使用了以下更命令式的逻辑样式:
this.db = window.openDatabase('myDb', '1.0', 'a comment', 5*1024*1024);
if (this.db) {
this.db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS myTable(...)',
[],
function(tx, rs) { },
function(tx, err) { alert("Error in create table occurred: " + err) }
);
});
}
希望对你也有用。
/弗雷德里克