Support non-standard Oracle port (#4147)

This commit is contained in:
Igor Savin 2020-12-08 00:47:00 +02:00 committed by GitHub
parent 073df48cc6
commit c47e00de64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,6 +81,24 @@ Client_Oracledb.prototype.prepBindings = function (bindings) {
}); });
}; };
function resolveConnectString(connectionSettings) {
if (connectionSettings.connectString) {
return connectionSettings.connectString;
}
if (!connectionSettings.port) {
return connectionSettings.host + '/' + connectionSettings.database;
}
return (
connectionSettings.host +
':' +
connectionSettings.port +
'/' +
connectionSettings.database
);
}
// Get a raw connection, called by the `pool` whenever a new // Get a raw connection, called by the `pool` whenever a new
// connection needs to be added to the pool. // connection needs to be added to the pool.
Client_Oracledb.prototype.acquireRawConnection = function () { Client_Oracledb.prototype.acquireRawConnection = function () {
@ -96,9 +114,9 @@ Client_Oracledb.prototype.acquireRawConnection = function () {
}; };
// In the case of external authentication connection string will be given // In the case of external authentication connection string will be given
oracleDbConfig.connectString = oracleDbConfig.connectString = resolveConnectString(
client.connectionSettings.connectString || client.connectionSettings
client.connectionSettings.host + '/' + client.connectionSettings.database; );
if (client.connectionSettings.prefetchRowCount) { if (client.connectionSettings.prefetchRowCount) {
oracleDbConfig.prefetchRows = client.connectionSettings.prefetchRowCount; oracleDbConfig.prefetchRows = client.connectionSettings.prefetchRowCount;
@ -142,10 +160,11 @@ Client_Oracledb.prototype.acquireRawConnection = function () {
throw new Error('not found oracledb.outFormat constants'); throw new Error('not found oracledb.outFormat constants');
} }
if (options.resultSet) { if (options.resultSet) {
connection.execute(sql, bindParams || [], options, function ( connection.execute(
err, sql,
result bindParams || [],
) { options,
function (err, result) {
if (err) { if (err) {
if (isConnectionError(err)) { if (isConnectionError(err)) {
connection.close().catch(function (err) {}); connection.close().catch(function (err) {});
@ -155,7 +174,11 @@ Client_Oracledb.prototype.acquireRawConnection = function () {
} }
const fetchResult = { rows: [], resultSet: result.resultSet }; const fetchResult = { rows: [], resultSet: result.resultSet };
const numRows = 100; const numRows = 100;
const fetchRowsFromRS = function (connection, resultSet, numRows) { const fetchRowsFromRS = function (
connection,
resultSet,
numRows
) {
resultSet.getRows(numRows, function (err, rows) { resultSet.getRows(numRows, function (err, rows) {
if (err) { if (err) {
if (isConnectionError(err)) { if (isConnectionError(err)) {
@ -179,12 +202,14 @@ Client_Oracledb.prototype.acquireRawConnection = function () {
}); });
}; };
fetchRowsFromRS(connection, result.resultSet, numRows); fetchRowsFromRS(connection, result.resultSet, numRows);
}); }
);
} else { } else {
connection.execute(sql, bindParams || [], options, function ( connection.execute(
err, sql,
result bindParams || [],
) { options,
function (err, result) {
if (err) { if (err) {
// dispose the connection on connection error // dispose the connection on connection error
if (isConnectionError(err)) { if (isConnectionError(err)) {
@ -195,7 +220,8 @@ Client_Oracledb.prototype.acquireRawConnection = function () {
} }
return cb(null, result); return cb(null, result);
}); }
);
} }
}); });
connection.executeAsync = function (sql, bindParams, options) { connection.executeAsync = function (sql, bindParams, options) {