Skip to content

Commit

Permalink
fix: Disconnect HANA tenant when deleted (#589)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Brucksch <[email protected]>
  • Loading branch information
BobdenOs and SamuelBrucksch authored May 7, 2024
1 parent cbcfe3b commit a107db9
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HANAService extends SQLService {
this.on(['BEGIN'], this.onBEGIN)
this.on(['COMMIT'], this.onCOMMIT)
this.on(['ROLLBACK'], this.onROLLBACK)
this.on(['SELECT', 'INSERT', 'UPSERT', 'UPDATE', 'DELETE'], this.onNOTFOUND)
return super.init()
}

Expand Down Expand Up @@ -135,8 +136,8 @@ class HANAService extends SQLService {
// REVISIT: add prepare options when param:true is used
const sqlScript = isLockQuery ? sql : this.wrapTemporary(temporary, withclause, blobs)
let rows = (values?.length || blobs.length > 0)
? await (await this.prepare(sqlScript, blobs.length)).all(values || [])
: await this.exec(sqlScript)
? await (await this.prepare(sqlScript, blobs.length)).all(values || [])
: await this.exec(sqlScript)

if (isLockQuery) {
// Fetch actual locked results
Expand Down Expand Up @@ -181,6 +182,19 @@ class HANAService extends SQLService {
}
}

async onNOTFOUND(req, next) {
try {
return await next()
} catch (err) {
// Ensure that the known entity still exists
if (!this.context.tenant && err.code === 259 && typeof req.query !== 'string') {
// Clear current tenant connection pool
this.disconnect(this.context.tenant)
}
throw err
}
}

// Allow for running complex expand queries in a single statement
wrapTemporary(temporary, withclauses, blobs) {
const blobColumn = b => `"${b.replace(/"/g, '""')}"`
Expand Down Expand Up @@ -1208,8 +1222,7 @@ class HANAService extends SQLService {
}

async _getProcedureMetadata(name, schema) {
const query = `SELECT PARAMETER_NAME FROM SYS.PROCEDURE_PARAMETERS WHERE SCHEMA_NAME = ${
schema?.toUpperCase?.() === 'SYS' ? `'SYS'` : 'CURRENT_SCHEMA'
const query = `SELECT PARAMETER_NAME FROM SYS.PROCEDURE_PARAMETERS WHERE SCHEMA_NAME = ${schema?.toUpperCase?.() === 'SYS' ? `'SYS'` : 'CURRENT_SCHEMA'
} AND PROCEDURE_NAME = '${name}' AND PARAMETER_TYPE IN ('OUT', 'INOUT') ORDER BY POSITION`
return await super.onPlainSQL({ query, data: [] })
}
Expand Down

0 comments on commit a107db9

Please sign in to comment.