Skip to content

Commit

Permalink
fix(hana): Align not found behavior in @cap-js/hana (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobdenOs authored Apr 22, 2024
1 parent 7db8df5 commit 54d2efb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class HANAService extends SQLService {
// REVISIT: the runtime always expects that the count is preserved with .map, required for renaming in mocks
return HANAService._arrayWithCount(rows, await this.count(query, rows))
}
return cqn.SELECT.one || query.SELECT.from.ref?.[0].cardinality?.max === 1 ? rows[0] || null : rows
return cqn.SELECT.one || query.SELECT.from.ref?.[0].cardinality?.max === 1 ? rows[0] : rows
}

async onINSERT({ query, data }) {
Expand Down
6 changes: 0 additions & 6 deletions hana/lib/drivers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ class HANADriver {
const stmt = await prep
let changes = await prom(stmt, 'exec')(values)
await this._sendStreams(stmt, streams)
// REVISIT: hana-client does not return any changes when doing an update with streams
// This causes the best assumption to be that the changes are one
// To get the correct information it is required to send a count with the update where clause
if (streams.length && changes === 0) {
changes = 1
}
return { changes }
},
runBatch: async params => {
Expand Down
20 changes: 17 additions & 3 deletions hana/lib/drivers/hana-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class HANAClientDriver extends driver {
rsStreamsProm.resolve = resolve
rsStreamsProm.reject = reject
})
rsStreams.catch(() => {})
rsStreams.catch(() => { })

rs._rowPosition = -1
const _next = prom(rs, 'next')
Expand Down Expand Up @@ -110,6 +110,20 @@ class HANAClientDriver extends driver {
}
}

ret.run = async params => {
const { values, streams } = this._extractStreams(params)
const stmt = await ret._prep
let changes = await prom(stmt, 'exec')(values)
await this._sendStreams(stmt, streams)
// REVISIT: hana-client does not return any changes when doing an update with streams
// This causes the best assumption to be that the changes are one
// To get the correct information it is required to send a count with the update where clause
if (streams.length && changes === 0) {
changes = 1
}
return { changes }
}

ret.proc = async (data, outParameters) => {
const stmt = await ret._prep
const rows = await prom(stmt, 'execQuery')(data)
Expand Down Expand Up @@ -161,7 +175,7 @@ class HANAClientDriver extends driver {
}

const resultSet = Array.isArray(rows) ? rows[0] : rows

// merge table output params into scalar params
const params = Array.isArray(outParameters) && outParameters.filter(md => !(md.PARAMETER_NAME in result))
if (params && params.length) {
Expand All @@ -174,7 +188,7 @@ class HANAClientDriver extends driver {
resultSet.nextResult()
}
}

return result
}

Expand Down

0 comments on commit 54d2efb

Please sign in to comment.