Advertisement
kotvalera83

javascript sqlite

Oct 10th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.99 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <script type="text/javascript">
  5. var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
  6. var msg;
  7. db.transaction(function (tx) {
  8.   tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
  9.   tx.executeSql('INSERT INTO LOGS (id, log) VALUES (3, "foobar")');
  10.   tx.executeSql('INSERT INTO LOGS (id, log) VALUES (4, "logmsg")');
  11.   msg = '<p>Log message created and row inserted.</p>';
  12.   document.querySelector('#status').innerHTML =  msg;
  13. });
  14.  
  15. db.transaction(function (tx) {
  16.   tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
  17.    var len = results.rows.length, i;
  18.    msg = "<p>Found rows: " + len + "</p>";
  19.    document.querySelector('#status').innerHTML +=  msg;
  20.    for (i = 0; i < len; i++){
  21.     msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
  22.      document.querySelector('#status').innerHTML +=  msg;
  23.    }
  24.  }, null);
  25. });
  26. </script>
  27. </head>
  28. <body>
  29. <div id="status" name="status">Status Message</div>
  30. </body>
  31. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement