Sql lite“给定的密钥不在字典中”

时间:2015-10-13 12:52:23

标签: javascript sqlite cordova windows-phone-8.1

我有一个使用sql lite插件的cordova windows应用程序。现在看两个查询做同样的事情:

"PRAGMA foreign_keys = ON";

不幸的是,第二个会在

时失败
example: PRIMARY KEY(setting, value)

不幸的是我的表有多列PRIMARY KEY,所以需要第二种语法。

let db = window.openDatabase("MFS", "", "MFS database", 52428800);
db.transaction((tx) => {
    let query1 = "CREATE TABLE IF NOT EXISTS Settings (setting TEXT PRIMARY KEY, value TEXT NOT NULL)",
        query2 = "CREATE TABLE IF NOT EXISTS Settings (setting TEXT, value TEXT NOT NULL, PRIMARY KEY(setting))";
    tx.executeSql(query1/*query2*/, [], (tx, result, query) => {
    }, (tx, err, query) => {
        alert(err.message);
    }
});

知道为什么以及如何解决?

代码:

white-space: normal; width: 80%;

1 个答案:

答案 0 :(得分:0)

我用CREATE TABLE IF NOT EXISTS Settings (setting INTEGER PRIMARY KEY ...定义了一个主键,它就像一个魅力:

db.transaction(createLocalTableSettings, errorLocalTable, successCreateLocalTableSettings);

function createLocalTableSettings(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS Settings (setting INTEGER PRIMARY KEY, value TEXT NOT NULL)');
}
function successCreateLocalTableSettings() {
        console.log('Settings Table successful created');
}
function errorLocalTable(err) {
        console.log("Error creating Settings Table! Processing SQL: " + err.sql + " Parameter: " + JSON.stringify(err.params));
}

希望这有帮助!