我正在创建一个phoneagap移动应用程序,并希望使用WebSql将数据存储在本地存储中。
所以我跟着这个......
Create Android App with SQLite using Phonegap + Jquery mobile
我已经成功创建了表,但是当我在按钮上单击时调用executeSql()方法时,它会给出错误(23)未授权。
我正在使用phonegap 3.5.0-0.20.4版本。这是最新的,在Android 4.2.2上运行, 我怎样才能解决这个问题,究竟是什么问题是???
这是我的代码: -
首先,我已经注册了一个deviceReady侦听器并使用
创建了一个数据库document.addEventListener("deviceready", onDeviceReady, false);
var db = window.openDatabase("abc_db", "1.0", "The ABC", 200000);
然后
function onDeviceReady(){
db.transaction(populateDB, errorCB, successCB);
}
//create table and insert some record
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Authentication (company_name TEXT NOT NULL, company_engineer TEXT NOT NULL, company_project TEXT NOT NULL, password TEXT NOT NULL)');
tx.executeSql('INSERT INTO Authentication(company_name, company_engineer, company_project, password) VALUES ("Company 1", "Engineer 1", "Project 1", "1111")');
tx.executeSql('INSERT INTO Authentication(company_name, company_engineer, company_project, password) VALUES ("Company 2", "Engineer 2", "Project 2", "2222")');
tx.executeSql('INSERT INTO Authentication(company_name, company_engineer, company_project, password) VALUES ("Company 3", "Engineer 3", "Project 3", "3333")');
}
//function will be called when an error occurred
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
//function will be called when process succeed
function successCB() {
alert("success!");
}
然后点击我正在使用的按钮...
funcion doLogin(){
password = document.forms["login"]["passowrd"].value;
company_name = document.forms["login"]["company"].value;
company_engineer = document.forms["login"]["company_engineer"].value;
company_project = document.forms["login"]["company_project"].value;
db = window.openDatabase("abc_db", "1.0", "The ABC", 200000);
db.transaction(queryDB,errorCB);
}
function queryDB(tx){
var qry = "SELECT * FROM Authentication WHERE company_name = '" + company_name + "' AND company_engineer = '" + company_engineer + "' AND company_project = '" + company_project + "' AND `password` = '" + password + "'";
tx.executeSql(qry ,[],querySuccess, errorGet);
}
function querySuccess(tx, result){
if(result.rows.length !== 0){
document.location.href = 'home.html';
} else {
alert('Invalid Username or password');
}
}