From 90ff568dc99b791a372ae4c6c83f94aee6bc005b Mon Sep 17 00:00:00 2001 From: Stephan Seidt Date: Thu, 28 May 2020 15:56:03 +0200 Subject: [PATCH] Use VACUUM INTO tempfile for export --- src/api.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/api.js b/src/api.js index 1484063d..2ff81f32 100644 --- a/src/api.js +++ b/src/api.js @@ -859,14 +859,12 @@ Module["onRuntimeInitialized"] = function onRuntimeInitialized() { Database.prototype["export"] = function exportDatabase() { var binaryDb; Object.values(this.statements).forEach(function each(stmt) { - stmt["free"](); + stmt["reset"](); }); - Object.values(this.functions).forEach(removeFunction); - this.functions = {}; - this.handleError(sqlite3_close_v2(this.db)); - binaryDb = FS.readFile(this.filename, { encoding: "binary" }); - this.handleError(sqlite3_open(this.filename, apiTemp)); - this.db = getValue(apiTemp, "i32"); + var exportFilename = "export_" + (0xffffffff * Math.random() >>> 0); + this.exec("VACUUM INTO ?", [exportFilename]); + binaryDb = FS.readFile(exportFilename, { encoding: "binary" }); + FS.unlink(exportFilename); return binaryDb; };