Skip to content

Load a database from the server Failed Error: file is encrypted or is not a database #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wuxingjun opened this issue Jan 2, 2017 · 9 comments

Comments

@wuxingjun
Copy link

Load a database from the server Failed Error: file is encrypted or is not a database
Here are my codes. test.db is in the root directory of my website
var xhr = new XMLHttpRequest();
xhr.open('GET', 'test.db', true);
xhr.responseType = 'arraybuffer';

xhr.onload = function(e) {
var uInt8Array = new Uint8Array(this.response);
var db = new SQL.Database(uInt8Array);
var contents = db.exec("SELECT * FROM testtable");
};
xhr.send();

@lovasoa
Copy link
Member

lovasoa commented Jan 2, 2017 via email

@wuxingjun
Copy link
Author

wuxingjun commented Jan 2, 2017

I ensure test.db is a database and not encrypted.

I can get data by upload sqlite file,but not from server

<input id="uploadInput" type="file" onchange="getfile()">
  function getfile() {
            var files = document.getElementById("uploadInput").files;
            var file = files[0];
            var fr = new FileReader();
            fr.onload = function () {
                var Uints = new Uint8Array(fr.result);
                var db = new window.SQL.Database(Uints);
                var res = db.exec("SELECT * FROM testtable");
                for (i = 0; i < res[0].values.length; i++) {
                    console.log(res[0].values[i] + ' ');
                }
            }
            fr.readAsArrayBuffer(file);
        }

@lovasoa
Copy link
Member

lovasoa commented Jan 2, 2017

What is this code you are giving ?

I think the problem is simply with how you fetch the DB file ? Can you give the full URL of your html file and the one of your database file ?

@wuxingjun
Copy link
Author

Here are my test codes and DB file
image
index.html
image
image

@lovasoa
Copy link
Member

lovasoa commented Jan 3, 2017 via email

@wuxingjun
Copy link
Author

I've found the reason.Permission Issue

@wuxingjun
Copy link
Author

That means Anyone can download the db file from website,right?

@lovasoa
Copy link
Member

lovasoa commented Jan 6, 2017 via email

@NameNull
Copy link

how to solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants