gpt4 book ai didi

javascript - Phonegap SYNTAX_ERR 上的 SQLITE 查询错误

转载 作者:可可西里 更新时间:2023-11-01 05:46:51 24 4
gpt4 key购买 nike

我正在尝试在带有 IOS5 的电话间隙 [cordova 1.7.0] 上使用 SQLITE 创建一个数据库。当我增加数据数量时,查询失败并输出错误。我跟着存储API步骤,所以我不知道是什么问题。我尝试增加数据库大小,但仍然没有用。

这是我的代码:

function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS SESSION');
tx.executeSql('CREATE TABLE IF NOT EXISTS SESSION (id unique, dayId, subject, Seq)');
tx.executeSql('INSERT INTO SESSION (id unique, dayId, subject, Seq) VALUES (1, 4, "English", 1)');
tx.executeSql('INSERT INTO SESSION (id unique, dayId, subject, Seq) VALUES (2, 1, "Math", 3)');
tx.executeSql('INSERT INTO SESSION (id unique, dayId, subject, Seq) VALUES (3, 2, "Social", 5)');
tx.executeSql('INSERT INTO SESSION (id unique, dayId, subject, Seq) VALUES (4, 6, "Science", 7)');
console.log('finished filling');
}

function queryDB(tx) {
tx.executeSql('SELECT * FROM SESSION', [], querySuccess, errorCB); //It doesn't come here
}

function querySuccess(tx, results) {
// Doesn't come here too
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).dayId);
}
}

function errorCB(err) {
console.log('error x'); //Fails here
console.log("Error processing SQL: "+err.code);
}

function errorQB(err) {
console.log(' Query error x');
console.log("Error processing SQL: "+err.code);
}

function successCB() {
var db = window.openDatabase("TimeTable", "1.0", "TimeTable" , 1000000);
cosole.log('start of success');
db.transaction(queryDB, errorQB);
console.log('success transaction'); //Didn't Success
}
function onDeviceReady() {
var db = window.openDatabase("TimeTable", "1.0", "TimeTable", 1000000);
db.transaction(populateDB, errorCB, successCB);
}

这是我的日志:

     [INFO] Error processing SQL: 5 //SYNTAX_ERR


你知道问题出在哪里吗?谢谢

最佳答案

我知道我做错了什么:

tx.executeSql('INSERT INTO SESSION (id ***unique***, dayId, subject, Seq) VALUES (1, 4, "English", 1)');

我也不应该在插入语句中写类型......所以当我删除它时,它工作正常。

关于javascript - Phonegap SYNTAX_ERR 上的 SQLITE 查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10538388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com