Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>web sql</title>
  4. <script src="websql.js"></script>
  5. </head>
  6. <body>
  7. myself <br>
  8. <button onclick="filldb()">fill db</button>
  9. <button onclick="dumpdb()">dump db</button>
  10. </body>
  11. </html>
  12. var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
  13.  
  14. function filldb()
  15. {
  16. db.transaction(function (tx) {
  17. tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
  18. tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "foobar")');
  19. tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');
  20. });
  21. }
  22.  
  23. function dumpdb()
  24. {
  25.  
  26. db.transaction(function (tx) {
  27. tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
  28. var len = results.rows.length, i;
  29. msg = "<p>Found rows: " + len + "</p>";
  30. console.log("msg: " + msg);
  31. for (i = 0; i < len; i++){
  32. console.log("results: " + results.rows.item(i).log );
  33. }
  34. }, null);
  35. });
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement