在我的应用程序中,我想在表中插入值。我在index.html文件的onDeviceReady()方法中创建了数据库。
<!DOCTYPE html>
<!-- Auto Generated with Sencha Architect -->
<!-- Modifications to this file will be overwritten. -->
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Teritree</title>
<script type="text/javascript" id="phonegap" src=
"cordova-2.0.0.js">
</script>
<script type="text/javascript" src="barcodescanner.js">
</script>
<script src="sencha-touch-all.js" type="text/javascript">
</script>
<link rel="stylesheet" type="text/css" href="app.css">
<script type="text/javascript" src="app/Ext.ux.touch.Rating.js">
</script>
<script type="text/javascript" src="app/app.js">
</script>
<script type="text/javascript">
Ext.Loader.setConfig({ disableCaching: false });
Ext.Ajax.setDisableCaching(false);
</script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
var mydb;
// Wait for PhoneGap to connect with the device
function onLoad() {
document.addEventListener("deviceready",onDeviceReady,false);
}
// PhoneGap is ready to be used!
function onDeviceReady() {
console.log("it is in ondevice ready method..");
mydb = window.openDatabase("teritreeDb", "1.0", "TestDB", 10000);
console.log("it is in ondevice ready method..1");
mydb.transaction(populateDB, errorCB, successCB);
console.log("it is in ondevice ready method..2");
}
function populateDB(tx) {
console.log("it is in populateDB----------1");
tx.executeSql('DROP TABLE IF EXISTS DEMO', function () {
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)', function () {
console.log("Table created");
});
});
// Transaction error callback
//
function errorCB(tx, err) {
alert("Error processing SQL: "+err);
}
// Transaction success callback
//
function successCB() {
alert("success!");
}
}
</script>
<script type="text/javascript">
if (!Ext.browser.is.WebKit) {
alert("The current browser is unsupported.\n\nSupported browsers:\n" +
"Google Chrome\n" +
"Apple Safari\n" +
"Mobile Safari (iOS)\n" +
"Android Browser\n" +
"BlackBerry Browser"
);
}
</script>
</head>
<body>
</body>
</html>
现在我有一个注册屏幕,在注册屏幕上我有提交按钮。所以如果我点击提交按钮,所有的细节都应该存储在数据库中,意味着在 DEMO 表中。所以在控制器中,我正在编写按钮事件,
onSubmitButtonTap : function(button, e, options) {
mydb = window.openDatabase("appDb", "1.0", "Test DB", 1000000);
mydb.transaction(storeCustomerDetails, error, success);
function storeCustomerDetails(tx)
{
tx.executeSql('insert into DEMO (id,data) values("1","Hello")');
tx.executeSql('insert into DEMO (id,data) values("2","Hello World")');
}
function error(){
alert("data is not inserted");
}
function success(){
alert("data is succesfully inserted");
}
},
但它给了我警报,没有插入数据。我点击了链接:Phonegap DB Link
请帮忙..