有没有办法检查 WebSQL 数据库中的表是否存在索引? 我正在使用
CREATE UNIQUE INDEX INDEX_GUID ON TABLE PERSONS
进行创作。但是如果索引已经存在,我会得到一个错误:
{
code: 5, // SYNTAX_ERR - from docs
message: "could not prepare statement (1 index INDEX_GUID already exists)"
}
对我来说最好的解决方案是列出表的所有索引。
我正在使用它,但这是一种解决方法。我希望错误信息总是英文的。
db.transaction(function (tx) {
tx.executeSql(
"CREATE UNIQUE INDEX INDEX_GUID ON TABLE PERSONS",
[],
function (tx, rs) {
// index created
},
function (tx, e) {
if (e.message.indexOf("already exists") == -1) {
// index not created - already exists
}
});
);
});
if (e.message.indexOf("already exists") == -1) {
应该是一个!=
即
db.transaction(function (tx) {
tx.executeSql(
"CREATE UNIQUE INDEX INDEX_GUID ON TABLE PERSONS",
[],
function (tx, rs) {
// index created
},
function (tx, e) {
if (e.message.indexOf("already exists") != -1) {
// index not created - already exists
}
});
);
});