node.js - javascript sql.js giving error Uncaught Error: file is encrypted or is not a database -


here <script> tag in html page giving me error:

uncaught error: file encrypted or not database

<script>    var file = "/data/mydb.sqlite";    var db = new sql.database(file);    db.run("select * webusers", function(err, rows) {       rows.foreach(function (row) {           console.log('webusers created user: '+row.username);       });     }); </script> 

as mentioned in comments, constructor doesn't take string, takes uint8array containing sqlite database.

one way use ajax request database arraybuffer , transform uint8array.

var file = "/data/mydb.sqlite";  var xhr = new xmlhttprequest(); xhr.open('get', file, true); xhr.responsetype = 'arraybuffer'; xhr.onload = function() {     var data = new uint8array(this.response);     var db = new sql.database(data);     db.run("select * webusers", function(err, rows) {         rows.foreach(function(row) {             console.log('webusers created user: ' + row.username);         });     }); }; xhr.send(); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -