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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<style>
	div {
		border: solid 2px #336699;
		margin: 10px;
		padding: 5px;
		border-radius: 5px;
		vertical-align: top;
		text-align: center;
		display: inline-block;
	}
	#container {
		background: #88BBFF;
		width: 480px;
	}
	#panel {
		background: #99CCFF;
		border: dotted 1px #4477AA;
		width: 90%;
		margin: 0px;
		text-align: left;
		font-size: 12px;
	}
</style>
<script>
try {
	var db = openDatabase(
		'account',
		'1.0',
		'Member Account Information',
		10*1024*1024,
		function(db) {
			db.changeVersion(
				'',
				'1.0',
				function(t) {
					t.executeSql("CREATE TABLE IF NOT EXISTS member (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(50) NOT NULL DEFAULT '', password VARCHAR(50) NOT NULL DEFAULT '')");
				},
				function(e) {
					alert(e.message);
				}
			);
		}
	);
} catch(e) {
	alert('Exception: '+e);
}
</script>
</head>
<body>
<input value="Create Table" id="createt" type="button"><br>
<input value="Drop Table" id="dropt" type="button"><br>
<input value="Insert Testing Data" id="set" type="button"><br>
<input value="Get Testing Data" id="get" type="button"><br>
<div id="panel"></div>
</body>
</html>
<script>
try {
	document.getElementById('set').addEventListener(
		'click',
		function(e) {
			db.transaction(
				function(t) {
					try {
						t.executeSql("INSERT OR REPLACE INTO member (name, password) VALUES ('a84718273','!a84718273')");
						t.executeSql("INSERT OR REPLACE INTO member (name, password) VALUES ('a84718274','!a84718274')");
						t.executeSql("INSERT OR REPLACE INTO member (name, password) VALUES ('a84718275','!a84718275')");
						t.executeSql("INSERT OR REPLACE INTO member (name, password) VALUES ('a84718276','!a84718276')");
					} catch(e) {
						document.getElementById('panel').innerHTML += '<li>' + e + '</li>';
					}
				},
				function(e) {
					document.getElementById('panel').innerHTML += '<li>' +e.message + '</li>';
				}
			);
		},
		false
	);
	document.getElementById('get').addEventListener(
		'click',
		function(e) {
			db.readTransaction(
				function(t) {
					t.executeSql(
						"SELECT * FROM member",
						[],
						function(t, r) {
							var str = '<ul>';
							for(var i=0,j=r.rows.length; i<j; i++) {
								str += '<li><ol>';
								for(var o in r.rows.item(i)) {
									str += '<li>';
									str += o + ' : ' + r.rows.item(i)[o];
									str += '</li>';
								}
								str += '</ol></li>';
							}
							str += '</ul>';
							document.getElementById('panel').innerHTML += str;
						}
					);
				},
				function(e) {
					document.getElementById('panel').innerHTML += '<li>' +e.message + '</li>';
					return false;
				}
			);
		},
		false
	);
	document.getElementById('dropt').addEventListener(
		'click',
		function() {
			db.transaction(
				function(t) {
					t.executeSql("DROP TABLE IF EXISTS member");
				},
				function(e) {
					document.getElementById('panel').innerHTML += '<li>' + e.message + '</li>';
				}
			);
		},
		false
	);
	document.getElementById('createt').addEventListener(
		'click',
		function() {
			db.transaction(
				function(t) {
					t.executeSql("CREATE TABLE IF NOT EXISTS member (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(50) NOT NULL DEFAULT '', password VARCHAR(50) NOT NULL DEFAULT '')");
				},
				function(e) {
					document.getElementById('panel').innerHTML += '<li>' + e.message + '</li>';
				}
			);
		},
		false
	);
} catch(e) {
	document.getElementById('panel').innerHTML += '<li>' + e + '</li>';
}
</script>