title: HTML5 - Export Web SQL database to a csv or txt file
body: <p>This is in reference to my question - <a href="https://stackoverflow.com/questions/13683183/attach-content-of-html5-websql-databse-to-email-using-javascript/13696877#13696877">Attach content of HTML5 WebSQL databse to email using javascript</a></p>
  
  <p>I have an HTML5 app that will run in Chrome browser. I need to export the data stored locally in the Web SQL DB and put it into a csv or txt file. </p>
  
  <p>I need to do this in the browser. Server side code is not an option. How can this be done usng javascript? Thanks</p>
  
  <p>EDIT:
  I found that one way of achieving this is through Data URI. So I have my result set from select query in the results object. How do I encode it to base 64 format?</p>
  
  <pre><code>       db.transaction(function (tx) {
         tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
         var len = results.rows.length, i;
         msg = "&lt;p&gt;Found rows: " + len + "&lt;/p&gt;";
         document.querySelector('#status').innerHTML +=  msg;
         for (i = 0; i &lt; len; i++){
            alert(results.rows.item(i).log );
         }
       }, null);
      });
  
      //Encode the results object to base64
      /* How can we do this? */
  
       &lt;a download="example.csv" href="data:application/csv;charset=utf-8, &lt;&lt;base64_encoded_data&gt;&gt;"&gt;Test&lt;/a&gt;
  </code></pre>