Skip to content

Commit

Permalink
chore: sql_simple_queries=3 for HANA queries
Browse files Browse the repository at this point in the history
For applications using `sql_simple_queries=2` and `@sap/hana-client` the
query results will properly reflect `true` and `false` for `boolean`
fields, but when using `hdb` as driver the `boolean` datatype is not
returned by the HANA protocol. While `hdb` has the data type defined
([code](https://github.com/SAP/node-hdb/blob/49c69673279655aa6534a9a5f38248ebdcfe36d3/lib/protocol/common/TypeCode.js#L45https://github.com/SAP/node-hdb/blob/49c69673279655aa6534a9a5f38248ebdcfe36d3/lib/protocol/common/TypeCode.js#L45))
for some reason HANA does not recognize `hdb` as a client capable of
handling `boolean` column types. Therefor the data type returned is
`tinyint` this change adjusts the data converter to output `true` and
`false` when using `sql_simple_queries=1`. Allowing the database service
to generate the same SQL statements for both `1` and `2`. Saving an
additional loop on the application to convert the numeric results to
booleans.
  • Loading branch information
BobdenOs authored Dec 16, 2024
1 parent b3743a1 commit 47d6977
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hana/lib/drivers/hdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ const { Readable, Stream, promises: { pipeline } } = require('stream')
const { StringDecoder } = require('string_decoder')
const { text } = require('stream/consumers')

const cds = require('@sap/cds')
const hdb = require('hdb')
const iconv = require('iconv-lite')

const { driver, prom, handleLevel } = require('./base')
const { isDynatraceEnabled: dt_sdk_is_present, dynatraceClient: wrap_client } = require('./dynatrace')

if (cds.env.features.sql_simple_queries === 3) {
// Make hdb return true / false
const Reader = require('hdb/lib/protocol/Reader.js')
Reader.prototype._readTinyInt = Reader.prototype.readTinyInt
Reader.prototype.readTinyInt = function () {
const ret = this._readTinyInt()
return ret == null ? ret : !!ret
}
}

const credentialMappings = [
{ old: 'certificate', new: 'ca' },
{ old: 'encrypt', new: 'useTLS' },
Expand Down

0 comments on commit 47d6977

Please sign in to comment.