Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>web sql</title>
- <script src="websql.js"></script>
- </head>
- <body>
- myself <br>
- <button onclick="filldb()">fill db</button>
- <button onclick="dumpdb()">dump db</button>
- </body>
- </html>
- var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
- function filldb()
- {
- db.transaction(function (tx) {
- tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
- tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")');
- tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');
- });
- }
- function dumpdb()
- {
- db.transaction(function (tx) {
- tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
- var len = results.rows.length, i;
- msg = "<p>Found rows: " + len + "</p>";
- console.log("msg: " + msg);
- for (i = 0; i < len; i++){
- console.log("results: " + results.rows.item(i).log );
- }
- }, null);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement