diff --git a/bindings/javascript/promise.js b/bindings/javascript/promise.js index 7ff274743..cd8d4d702 100644 --- a/bindings/javascript/promise.js +++ b/bindings/javascript/promise.js @@ -190,6 +190,10 @@ class Database { * @param {string} sql - The SQL statement string to execute. */ exec(sql) { + if (!this.open) { + throw new TypeError("The database connection is not open"); + } + try { this.db.batch(sql); } catch (err) { diff --git a/bindings/javascript/sync.js b/bindings/javascript/sync.js index 555d2c245..a3bd934fc 100644 --- a/bindings/javascript/sync.js +++ b/bindings/javascript/sync.js @@ -190,6 +190,10 @@ class Database { * @param {string} sql - The SQL statement string to execute. */ exec(sql) { + if (!this.open) { + throw new TypeError("The database connection is not open"); + } + try { this.db.batch(sql); } catch (err) {