diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index 4e9d29885..7d7f57cfe 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -236,7 +236,7 @@ class HANAService extends SQLService { const row = rows[i] const expands = JSON.parse(row._expands_) const blobs = JSON.parse(row._blobs_) - const data = Object.assign(JSON.parse(row._json_), expands, blobs) + const data = Object.assign(JSON.parse(row._json_ || '{}'), expands, blobs) Object.keys(blobs).forEach(k => (data[k] = row[k] || data[k])) // REVISIT: try to unify with handleLevel from base driver used for streaming @@ -667,6 +667,8 @@ class HANAService extends SQLService { const _stream = entries => { const stream = Readable.from(this.INSERT_entries_stream(entries, 'hex'), { objectMode: false }) + stream.setEncoding('utf-8') + stream.type = 'json' stream._raw = entries return stream } diff --git a/hana/lib/drivers/hdb.js b/hana/lib/drivers/hdb.js index 212115444..5d8630c7c 100644 --- a/hana/lib/drivers/hdb.js +++ b/hana/lib/drivers/hdb.js @@ -1,4 +1,4 @@ -const { Readable, Stream } = require('stream') +const { Readable, Stream, promises: { pipeline } } = require('stream') const { StringDecoder } = require('string_decoder') const { text } = require('stream/consumers') @@ -22,7 +22,6 @@ class HDBDriver extends driver { */ constructor(creds) { creds = { - useCesu8: false, fetchSize: 1 << 16, // V8 default memory page size ...creds, } @@ -138,7 +137,7 @@ class HDBDriver extends driver { _getResultForProcedure(rows, outParameters) { // on hdb, rows already contains results for scalar params const isArray = Array.isArray(rows) - const result = isArray ? {...rows[0]} : {...rows} + const result = isArray ? { ...rows[0] } : { ...rows } // merge table output params into scalar params const args = isArray ? rows.slice(1) : [] @@ -158,6 +157,14 @@ class HDBDriver extends driver { const streams = [] values = values.map((v, i) => { if (v instanceof Stream) { + if (this._creds.useCesu8 !== false && v.type === 'json') { + const encode = iconv.encodeStream('cesu8') + v.setEncoding('utf-8') + // hdb will react to the stream error no need to handle it twice + pipeline(v, encode).catch(() => { }) + return encode + } + streams[i] = v const iterator = v[Symbol.asyncIterator]() return Readable.from(iterator, { objectMode: false })