4
Licensed to the Apache Software Foundation (ASF) under one
5
or more contributor license agreements. See the NOTICE file
6
distributed with this work for additional information
7
regarding copyright ownership. The ASF licenses this file
8
to you under the Apache License, Version 2.0 (the
9
"License"); you may not use this file except in compliance
10
with the License. You may obtain a copy of the License at
12
http://www.apache.org/licenses/LICENSE-2.0
14
Unless required by applicable law or agreed to in writing,
15
software distributed under the License is distributed on an
16
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
KIND, either express or implied. See the License for the
18
specific language governing permissions and limitations
26
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
27
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
28
<title>Cordova Mobile Spec</title>
29
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
30
<script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
33
<script type="text/javascript" charset="utf-8">
35
var deviceReady = false;
37
//-------------------------------------------------------------------------
39
//-------------------------------------------------------------------------
41
var callDatabase = function() {
42
db = openDatabase("mydb", "1.0", "Apache Cordova Demo", 20000);
44
databaseOutput("Database could not be opened.");
47
databaseOutput("Database opened.");
48
db.transaction(function (tx) {
49
tx.executeSql('DROP TABLE IF EXISTS DEMO');
50
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)', [],
51
function(tx,results) { console.log("Created table"); },
52
function(tx,err) { alert("Error creating table: "+err.message); });
53
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")', [],
54
function(tx,results) { console.log("Insert row1 success"); },
55
function(tx,err) { alert("Error adding 1st row: "+err.message); });
56
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")', [],
57
function(tx,results) { console.log("Insert row2 success"); },
58
function(tx,err) { alert("Error adding 2nd row: "+err.message); });
59
databaseOutput("Data written to DEMO table.");
60
console.log("Data written to DEMO table.");
62
tx.executeSql('SELECT * FROM DEMO', [], function (tx, results) {
63
var len = results.rows.length;
64
var text = "DEMO table: " + len + " rows found.<br>";
65
text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
66
for (var i=0; i<len; i++){
67
text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>";
69
text = text + "</table>";
71
}, function(tx, err) {
72
alert("Error processing SELECT * SQL: "+err.message);
74
tx.executeSql('SELECT ID FROM DEMO', [], function (tx, results) {
75
var len = results.rows.length;
76
var text = "DEMO table: " + len + " rows found.<br>";
77
text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
78
for (var i=0; i<len; i++){
79
text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + "</td></tr>";
81
text = text + "</table>";
83
}, function(tx, err) {
84
alert("Error processing SELECT ID SQL: "+err.message);
89
console.log("Transaction failed: " + err.message);
95
var readDatabase = function() {
97
db = openDatabase("mydb", "1.0", "Apache Cordova Demo", 20000);
99
databaseOutput("Database could not be opened.");
103
db.transaction(function (tx) {
104
tx.executeSql('SELECT * FROM DEMO WHERE id=2', [], function (tx, results) {
105
var len = results.rows.length;
106
var text = "DEMO table: " + len + " rows found.<br>";
107
text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>";
108
for (var i=0; i<len; i++){
109
text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>";
111
text = text + "</table>";
112
databaseOutput(text);
113
}, function(tx, err) {
114
alert("Error processing SELECT * WHERE id=2 SQL: "+err.message);
119
var databaseOutput = function(s) {
120
var el = document.getElementById("database_results");
121
el.innerHTML = el.innerHTML + s + "<br>";
125
* Function called when page has finished loading.
128
document.addEventListener("deviceready", function() {
130
console.log("Device="+device.platform+" "+device.version);
132
window.setTimeout(function() {
134
alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
142
<body onload="init();" id="stage" class="theme">
144
<h1>HTML5 Database</h1>
147
<span id="database_results"></span>
150
<div class="btn large" onclick="callDatabase();">Create, Add, Read Database</div>
151
<div class="btn large" onclick="readDatabase();">Read Database</div>
152
<h2> </h2><div class="backBtn" onclick="backHome();">Back</div>