0

I dont know if I forget something totally basic here but in my HTML:

<script src="scripts/sql.js" type="text/javascript"></script>

and my js-file looks like this:

var xhr = new XMLHttpRequest();
xhr.open('GET', '123.sqlite3', true);
xhr.responseType = 'arraybuffer';

xhr.onload = function(e) {
  var uInt8Array = new Uint8Array(this.response);
  db = new SQL.Database(uInt8Array);
};
xhr.send();

function getSearchFromSQL() {
    result = db.exec("SELECT * FROM data") ;
    document.getElementById('output').innerHTML = result ;
}

As a result i only get

[object Object]

Netbeans tells me that the global variables db and SQL are not declared but I just cant figure out why, since its in the sql.js

whatever.idc
  • 92
  • 1
  • 1
  • 10
  • `db.exec()` is an async function, the value it returns is a promise, not the result of the query. – Barmar Jun 22 '17 at 16:50
  • I dont know why its marked a duplicate since you didnt even answer my question and the marked question has nothing to do with sql.js – whatever.idc Jun 22 '17 at 16:58
  • The problem is with getting the result from an asynchronous function. The linked question explains how to do that in general. Why do you think sql.js works differently? – Barmar Jun 22 '17 at 18:28

0 Answers0