OLD | NEW |
| (Empty) |
1 <html> | |
2 <script> | |
3 | |
4 // Open a Web SQL database. | |
5 var g_db = null; | |
6 if (typeof window.openDatabase == "undefined") { | |
7 document.write("Error: Web SQL databases are not supported."); | |
8 } | |
9 try { | |
10 g_db = openDatabase("test", "1.0", "test database", 1024 * 1024); | |
11 } catch(err) { | |
12 document.write("Error: cannot open database."); | |
13 } | |
14 | |
15 // Creates a table named "table1" with one text column named "data". | |
16 function createTable() { | |
17 if (!g_db) | |
18 return; | |
19 g_db.transaction( | |
20 function(tx) { | |
21 tx.executeSql("CREATE TABLE table1 (data TEXT)"); | |
22 }, | |
23 function(error) { | |
24 sendValueToTest(error); | |
25 }, | |
26 function() { | |
27 sendValueToTest("done"); | |
28 }); | |
29 } | |
30 | |
31 // Inserts a record into the database. | |
32 function insertRecord(text) { | |
33 g_db.transaction( | |
34 function(tx) { | |
35 tx.executeSql("INSERT INTO table1 VALUES (?)", [text]); | |
36 }, | |
37 function(error) { | |
38 sendValueToTest(error); | |
39 }, | |
40 function() { | |
41 sendValueToTest("done"); | |
42 }); | |
43 } | |
44 | |
45 // Gets all the records in the database, ordered by their age. | |
46 function getRecords() { | |
47 g_db.readTransaction(function(tx) { | |
48 tx.executeSql( | |
49 "SELECT data FROM table1 ORDER BY ROWID", | |
50 [], | |
51 function(tx, result) { | |
52 items = ""; | |
53 for (var i = 0; i < result.rows.length; i++) { | |
54 if (items != "") | |
55 items += ", "; | |
56 items += result.rows.item(i).data; | |
57 } | |
58 sendValueToTest(items); | |
59 }, | |
60 function(tx, error) { | |
61 sendValueToTest(error); | |
62 }); | |
63 }); | |
64 } | |
65 | |
66 function sendValueToTest(value) { | |
67 //alert(value); | |
68 window.domAutomationController.setAutomationId(0); | |
69 window.domAutomationController.send(value); | |
70 } | |
71 | |
72 </script> | |
73 | |
74 <body> | |
75 This page is used for testing Web SQL databases. | |
76 </body> | |
77 </html> | |
OLD | NEW |