mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 22:36:01 +00:00
Enhance binary data handling in Oracle driver and adjust dumper for byte array values
This commit is contained in:
@@ -37,6 +37,15 @@ function zipDataRow(rowArray, columns) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
function modifyRow(row, columns) {
|
||||
columns.forEach(col => {
|
||||
if (Buffer.isBuffer(row[col.columnName])) {
|
||||
row[col.columnName] = { $binary: { base64: row[col.columnName].toString('base64') } };
|
||||
}
|
||||
});
|
||||
return row;
|
||||
}
|
||||
|
||||
let oracleClientInitialized = false;
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
@@ -106,7 +115,7 @@ const driver = {
|
||||
const res = await dbhan.client.execute(sql);
|
||||
try {
|
||||
const columns = extractOracleColumns(res.metaData);
|
||||
return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns };
|
||||
return { rows: (res.rows || []).map(row => modifyRow(zipDataRow(row, columns), columns)), columns };
|
||||
} catch (err) {
|
||||
return {
|
||||
rows: [],
|
||||
@@ -134,7 +143,7 @@ const driver = {
|
||||
if (!wasHeader) {
|
||||
columns = extractOracleColumns(row);
|
||||
if (columns && columns.length > 0) {
|
||||
options.recordset(columns);
|
||||
options.recordset(columns, { engine: driverBase.engine });
|
||||
}
|
||||
wasHeader = true;
|
||||
}
|
||||
@@ -147,11 +156,11 @@ const driver = {
|
||||
if (!wasHeader) {
|
||||
columns = extractOracleColumns(row);
|
||||
if (columns && columns.length > 0) {
|
||||
options.recordset(columns);
|
||||
options.recordset(columns, { engine: driverBase.engine });
|
||||
}
|
||||
wasHeader = true;
|
||||
}
|
||||
options.row(zipDataRow(row, columns));
|
||||
options.row(modifyRow(zipDataRow(row, columns), columns));
|
||||
});
|
||||
|
||||
query.on('end', () => {
|
||||
@@ -214,9 +223,9 @@ const driver = {
|
||||
|
||||
if (rows && metaData) {
|
||||
const columns = extractOracleColumns(metaData);
|
||||
options.recordset(columns);
|
||||
options.recordset(columns, { engine: driverBase.engine });
|
||||
for (const row of rows) {
|
||||
options.row(zipDataRow(row, columns));
|
||||
options.row(modifyRow(zipDataRow(row, columns), columns));
|
||||
}
|
||||
} else if (rowsAffected) {
|
||||
options.info({
|
||||
@@ -302,6 +311,7 @@ const driver = {
|
||||
if (columns && columns.length > 0) {
|
||||
pass.write({
|
||||
__isStreamHeader: true,
|
||||
engine: driverBase.engine,
|
||||
...(structure || { columns }),
|
||||
});
|
||||
}
|
||||
@@ -310,7 +320,7 @@ const driver = {
|
||||
});
|
||||
|
||||
query.on('data', row => {
|
||||
pass.write(zipDataRow(row, columns));
|
||||
pass.write(modifyRow(zipDataRow(row, columns), columns));
|
||||
});
|
||||
|
||||
query.on('end', () => {
|
||||
|
||||
@@ -136,9 +136,9 @@ class Dumper extends SqlDumper {
|
||||
// else super.putValue(value);
|
||||
// }
|
||||
|
||||
// putByteArrayValue(value) {
|
||||
// this.putRaw(`e'\\\\x${arrayToHexString(value)}'`);
|
||||
// }
|
||||
putByteArrayValue(value) {
|
||||
this.putRaw(`HEXTORAW('${arrayToHexString(value)}')`);
|
||||
}
|
||||
|
||||
putValue(value, dataType) {
|
||||
if (dataType?.toLowerCase() == 'timestamp') {
|
||||
|
||||
Reference in New Issue
Block a user