title: Trouble reading sqlite3 database columns of type blob with sql.js
body: <p>So i am using the sql.js library i.e. the port of sqlite in javascript which can be found here  <a href="https://github.com/kripken/sql.js" rel="nofollow noreferrer">https://github.com/kripken/sql.js</a>.</p>
  <p>This is my code to open and read the database that comes from a flat file store locally.</p>
  <p>First the file a local file is selected via this HTML</p>
  <pre><code>&lt;input type=&quot;file&quot; id=&quot;input&quot; onchange=&quot;handleFiles(this.files)&quot;&gt;
  </code></pre>
  <p>The js code behind the scenes is as follows,</p>
  <pre><code>function handleFiles(files) {   
    var file = files[0]; 
    var reader = new FileReader();
    reader.readAsBinaryString(file);
    openDbOnFileLoad(reader); 
    function openDbOnFileLoad(reader){
      setTimeout(function () {
      if(reader.readyState == reader.DONE) {
        //console.log(reader.result);
        db = SQL.open(bin2Array(reader.result));
        execute(&quot;SELECT * FROM table&quot;);
      } else {
        //console.log(&quot;Waiting for loading...&quot;);
        openDbOnFileLoad(reader);
      }
      }, 500);    
    }
    
  }
  
  function execute(commands) {
    commands = commands.replace(/\n/g, '; ');
    try {
      var data = db.exec(commands);
      console.log(data);
    } catch(e) {
      console.log(e);
    }
  }
  function bin2Array(bin) {
    'use strict';
    var i, size = bin.length, ary = [];
    for (i = 0; i &lt; size; i++) {
        ary.push(bin.charCodeAt(i) &amp; 0xFF);
    }
    return ary;
  }
  </code></pre>
  <p>Now this works and i can access all the columns and values in the database, however there is one column which is of type blob and that just shows up as empty. Any ideas of how i can access the contents of this blob?</p>
  <p><strong>The correct answer!</strong></p>
  <p>So what I was trying to ask in this question is simply how to read the contents of a column of type blob using sql.js. The correct answer is to specify the column names in the question and for the column that contains data of type blob, get its contents using the hex function i.e. select column1,hex(column2) from table. It was by no means a question about the most efficient way of doing this. I have also written a <a href="https://mydaytodo.com/reading-a-sqlite-database-using-client-side-javascript/" rel="nofollow noreferrer">blog post</a> about this.</p>