我正在尝试使用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
你知道问题是什么吗? 谢谢
答案 0 :(得分:3)
我知道我做错了什么:
tx.executeSql('INSERT INTO SESSION (id ***unique***, dayId, subject, Seq) VALUES (1, 4, "English", 1)');
我不应该在insert语句中写入类型...所以当我删除它时,它工作正常。