~zaspire/cordova-ubuntu-tests/disable-more-tests

« back to all changes in this revision

Viewing changes to www/sql/index.html

  • Committer: VĂ­ctor R. Ruiz
  • Date: 2013-07-25 13:09:34 UTC
  • Revision ID: victor.ruiz@canonical.com-20130725130934-d4q95mh8eehbv363
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
2
<!--
 
3
 
 
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
 
11
 
 
12
   http://www.apache.org/licenses/LICENSE-2.0
 
13
 
 
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
 
19
 under the License.
 
20
 
 
21
-->
 
22
 
 
23
 
 
24
<html>
 
25
  <head>
 
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>      
 
31
 
 
32
      
 
33
<script type="text/javascript" charset="utf-8">
 
34
 
 
35
    var deviceReady = false;
 
36
 
 
37
    //-------------------------------------------------------------------------
 
38
    // HTML5 Database
 
39
    //-------------------------------------------------------------------------
 
40
    var db;
 
41
    var callDatabase = function() {
 
42
        db = openDatabase("mydb", "1.0", "Apache Cordova Demo", 20000);
 
43
        if (db === null) {
 
44
            databaseOutput("Database could not be opened.");
 
45
            return;
 
46
        }
 
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.");
 
61
 
 
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>";
 
68
                }
 
69
                text = text + "</table>";
 
70
                databaseOutput(text);
 
71
            }, function(tx, err) {
 
72
                alert("Error processing SELECT * SQL: "+err.message);
 
73
            });
 
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>";
 
80
                }
 
81
                text = text + "</table>";
 
82
                databaseOutput(text);
 
83
            }, function(tx, err) {
 
84
                alert("Error processing SELECT ID SQL: "+err.message);
 
85
            });
 
86
            
 
87
        },
 
88
        function(err) {
 
89
            console.log("Transaction failed: " + err.message);
 
90
        });
 
91
 
 
92
 
 
93
    };
 
94
 
 
95
    var readDatabase = function() {
 
96
        if (!db) {
 
97
            db = openDatabase("mydb", "1.0", "Apache Cordova Demo", 20000);
 
98
            if (db === null) {
 
99
                databaseOutput("Database could not be opened.");
 
100
                return;
 
101
            }
 
102
        }
 
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>";
 
110
                }
 
111
                text = text + "</table>";
 
112
                databaseOutput(text);
 
113
            }, function(tx, err) {
 
114
                alert("Error processing SELECT * WHERE id=2 SQL: "+err.message);
 
115
            });
 
116
        });
 
117
    }
 
118
 
 
119
    var databaseOutput = function(s) {
 
120
        var el = document.getElementById("database_results");
 
121
        el.innerHTML = el.innerHTML + s + "<br>";
 
122
    };
 
123
    
 
124
    /**
 
125
     * Function called when page has finished loading.
 
126
     */
 
127
    function init() {
 
128
        document.addEventListener("deviceready", function() {
 
129
                deviceReady = true;
 
130
                console.log("Device="+device.platform+" "+device.version);
 
131
            }, false);
 
132
        window.setTimeout(function() {
 
133
                if (!deviceReady) {
 
134
                        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
 
135
                }
 
136
        },1000);
 
137
    }
 
138
 
 
139
</script>
 
140
 
 
141
  </head>
 
142
  <body onload="init();" id="stage" class="theme">
 
143
  
 
144
    <h1>HTML5 Database</h1>   
 
145
    <div id="info">
 
146
        <b>Results:</b><br>
 
147
        <span id="database_results"></span>
 
148
    </div>
 
149
    <h2>Action</h2>
 
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>    
 
153
  </body>
 
154
</html>