-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
99 lines (73 loc) · 3.03 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html manifest="offline.manifest">
<head>
<meta charset="utf-8">
<title>Exemplo Storage HTML5</title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<script type="text/javascript" src="js/migrator.js"></script>
<script type="text/javascript">
if (window.openDatabase) {
var db = openDatabase("banco2", "", "Exemplo Web SQL", 100000);
// now db is a database object: http://dev.w3.org/html5/webdatabase/#database
var M = new Migrator(db);
M.setDebugLevel(Migrator.DEBUG_HIGH);
M.migration(1, function(t) {
// t here is a transaction object: http://dev.w3.org/html5/webdatabase/#sqltransaction
t.executeSql("create table user(id integer primary key, name text)");
t.executeSql("insert into user(name) values('Andreus')");
});
M.migration(2, function(t) {
t.executeSql("alter table user add column fone text");
t.executeSql("update user set fone = '5555-5555' where name == 'Andreus'");
});
M.migration(3, function(t) {
t.executeSql("insert into user(name, fone) values('Mariana', '5555-1234')");
t.executeSql("update user set fone = '5555-5556' where name == 'Andreus'");
});
M.migration(4, function(t) {
t.executeSql("insert into user(name, fone) values('Beth', '2222-1234')");
});
M.migration(5, function(t) {
t.executeSql("insert into user(name, fone) values('claudio', '6666-1234')");
});
// This executes the applicable transactions
M.execute();
} else {
$("p:eq(0)").text("Oops! HTML5 databases are not supported with your browser.");
}
function buscar() {
M.whenDone(function() {
db.transaction(function(t) {
t.executeSql("select id, name, fone from user", [], function(t, res) {
$('table.agenda > tbody').html();
var rows = res.rows;
var addressTable = $("table.agenda > tbody");
for (var i = 0; i < rows.length; i++) {
var row = rows.item(i);
var domRow = $("<tr><td>"+row.id+"</td><td>"+row.name+"</td><td>"+row.fone+"</td></tr>");
domRow.appendTo(addressTable);
}
});
});
});
}
$(function () {
buscar();
});
</script>
<h1>Agenda</h1>
<table class="agenda" width="100%" cellpadding="5" border="1">
<thead>
<tr>
<th>ID</th>
<th>Nome</th>
<th>Fone</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>