ios android phonegap 数据库
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo",1000);
db.transaction(function(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
}, errorCB);
//
var record=0;
function inser_value(tx) {
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
alert("insert");
}
function querySuccess(tx, results) {
var len = results.rows.length;
if(len==0){
alert("no record");
record==1;
}else{
alert("has record");
for (var i=0; i<len; i++){
alert("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
}
}
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
function queryData() {
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 1000);
db.transaction(function(tx){
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}, errorCB);
}
function just_in_record(){
queryData();
}
function inser_record(){
db.transaction(inser_value, errorCB);
}