diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index ef908e408..6df6e59dc 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -37,6 +37,20 @@ class HANAService extends SQLService { this.on(['COMMIT'], this.onCOMMIT) this.on(['ROLLBACK'], this.onROLLBACK) this.on(['SELECT', 'INSERT', 'UPSERT', 'UPDATE', 'DELETE'], this.onNOTFOUND) + + // TODO: remove + this.options._max_statement_count = 10 + + // destroy connections that have exceeded the max statement count + const { _max_statement_count } = this.options + if (_max_statement_count) { + const { release, destroy } = this + this.release = function () { + if (this.dbc?._native?._statement_count > _max_statement_count) return destroy.call(this) + return release.call(this) + } + } + return super.init() } @@ -1366,19 +1380,15 @@ SELECT ${mixing} FROM JSON_TABLE(SRC.JSON, '$' COLUMNS(${extraction}) ERROR ON E onCOMMIT() { DEBUG?.('COMMIT') - this.dbc?.statements?.forEach(stmt => stmt - .then(stmt => stmt.drop()) - .catch(() => { }) - ) + if (!this.options._max_statement_count) + this.dbc?.statements?.forEach(stmt => stmt.then(stmt => stmt.drop()).catch(() => {})) return this.dbc?.commit() } onROLLBACK() { DEBUG?.('ROLLBACK') - this.dbc?.statements?.forEach(stmt => stmt - .then(stmt => stmt.drop()) - .catch(() => { }) - ) + if (!this.options._max_statement_count) + this.dbc?.statements?.forEach(stmt => stmt.then(stmt => stmt.drop()).catch(() => {})) return this.dbc?.rollback() } diff --git a/hana/lib/drivers/base.js b/hana/lib/drivers/base.js index 428986cf2..ed66bc329 100644 --- a/hana/lib/drivers/base.js +++ b/hana/lib/drivers/base.js @@ -17,10 +17,12 @@ class HANADriver { * @returns {import('@cap-js/db-service/lib/SQLService').PreparedStatement} */ async prepare(sql) { + this._native._statement_count ??= 0 const prep = module.exports.prom( this._native, 'prepare', )(sql).then(stmt => { + this._native._statement_count++ stmt._parentConnection = this._native return stmt })