PhoneGap的机器人 - 填充一次数据库和QUOT;错误处理SQL:1" [英] phoneGap Android - Populate database once "Error processing SQL:1"
本文介绍了PhoneGap的机器人 - 填充一次数据库和QUOT;错误处理SQL:1"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,以避免填充数据库,如果数据库存在,但是当我尝试取消这条线在我的code,我得到的错误处理SQL:1
tx.executeSql(DROP TABLE IF EXISTS DEMO);
这是我的整个填充功能
函数populateDB(德克萨斯州){
tx.executeSql(DROP TABLE IF EXISTS DEMO);
tx.executeSql(CREATE TABLE IF NOT EXISTS DEMO(ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,字文NOT NULL');
tx.executeSql(INSERT INTO DEMO(标识,字)VALUES(1,苹果)');
tx.executeSql(INSERT INTO DEMO(标识,字)VALUES(2,橙)');
}
解决方案
您的功能设置将在下文纠正问题。现在应该工作。
函数populateDB(德克萨斯州){
isTableExists(德克萨斯州,DEMO,功能(状态){
如果(!状态){
警报(表不存在,创建一);
tx.executeSql(CREATE TABLE DEMO(ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,千字TEXT NOT NULL,eword TEXT NOT NULL,代词TEXT NOT NULL,整数水平NOT NULL));
tx.executeSql(INSERT INTO DEMO(千字,eword,代词,水平)VALUES(苹果,,,1)');
tx.executeSql(INSERT INTO DEMO(千字,eword,代词,水平)VALUES(橙色,,,2));
} 其他 {
警报(表中,下探测试);
tx.executeSql(DROP TABLE DEMO);
}
});
}
功能isTableExists(德克萨斯州中,TableName,回调){
tx.executeSql(SELECT * FROM DEMO,[],功能(德克萨斯州,结果集){
如果(resultSet.rows.length&所述; = 0){
回调(假);
} 其他 {
回调(真正的);
}
},功能(错误){
回调(假);
});
}
I am trying to avoid populate the database if the database exists but when I try to cancel this line in my code I get "Error processing SQL:1"
tx.executeSql('DROP TABLE IF EXISTS DEMO');
this is my whole populate function
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, word TEXT NOT NULL');
tx.executeSql('INSERT INTO DEMO (id, word) VALUES ("1", "Apple")');
tx.executeSql('INSERT INTO DEMO (id, word) VALUES ("2", "Orange")');
}
解决方案
Your function has set of issues which are corrected below. It should work now.
function populateDB(tx) {
isTableExists(tx, "DEMO", function(status) {
if (!status) {
alert("table not exist, creating one");
tx.executeSql('CREATE TABLE DEMO (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, kword TEXT NOT NULL, eword TEXT NOT NULL, pronoun TEXT NOT NULL, level INTEGER NOT NULL)');
tx.executeSql('INSERT INTO DEMO (kword, eword, pronoun, level) VALUES ("Apple", "", "", 1)');
tx.executeSql('INSERT INTO DEMO (kword, eword, pronoun, level) VALUES ("Orange", "", "", 2 )');
} else {
alert("table exist, dropping for test");
tx.executeSql('DROP TABLE DEMO');
}
});
}
function isTableExists(tx, tableName, callback) {
tx.executeSql('SELECT * FROM DEMO', [], function(tx, resultSet) {
if (resultSet.rows.length <= 0) {
callback(false);
} else {
callback(true);
}
}, function(err) {
callback(false);
});
}
这篇关于PhoneGap的机器人 - 填充一次数据库和QUOT;错误处理SQL:1&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文