sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

How to open a export database file?

Open alexwenbj opened this issue 7 years ago • 2 comments

I exported the database from memory and save it on server.The next time,when i re-open the exported file via XMLHttpRequest,it said the file is not a database file.How can I re-use the saved data? The code to export and post to server:

        var data = db.export();
 	
 	db.close();
 	$.post("saveDb.php",{
 		data:data
 	},function(result){
	    console.log(result);
	});

On the server,I used the http_put_contents() to save the data to file "sqlite.db". The code to load the saved db file is as below:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'sqlite.db', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
	var uInt8Array = new Uint8Array(this.response);
	db = new SQL.Database(uInt8Array);
	//......
};
xhr.send();

Then it raise an error:Uncaught Error: file is not a database

Thank you.

alexwenbj avatar Jul 01 '18 10:07 alexwenbj

Hello ! I wonder if you have found a solution ? I 'm using sql.js and need to export the user DB to a PHP server, thank you !

estellederrien avatar Feb 11 '19 18:02 estellederrien

Hello ! I wonder if you have found a solution ? I 'm using sql.js and need to export the user DB to a PHP server, thank you !

Nope.

alexwenbj avatar Feb 18 '19 10:02 alexwenbj