diff --git a/lib/dialects/oracledb/index.js b/lib/dialects/oracledb/index.js index 40b70085..a41c8e72 100644 --- a/lib/dialects/oracledb/index.js +++ b/lib/dialects/oracledb/index.js @@ -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 // connection needs to be added to the pool. 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 - oracleDbConfig.connectString = - client.connectionSettings.connectString || - client.connectionSettings.host + '/' + client.connectionSettings.database; + oracleDbConfig.connectString = resolveConnectString( + client.connectionSettings + ); if (client.connectionSettings.prefetchRowCount) { oracleDbConfig.prefetchRows = client.connectionSettings.prefetchRowCount; @@ -142,60 +160,68 @@ Client_Oracledb.prototype.acquireRawConnection = function () { throw new Error('not found oracledb.outFormat constants'); } if (options.resultSet) { - connection.execute(sql, bindParams || [], options, function ( - err, - result - ) { - if (err) { - if (isConnectionError(err)) { - connection.close().catch(function (err) {}); - connection.__knex__disposed = err; - } - return cb(err); - } - const fetchResult = { rows: [], resultSet: result.resultSet }; - const numRows = 100; - const fetchRowsFromRS = function (connection, resultSet, numRows) { - resultSet.getRows(numRows, function (err, rows) { - if (err) { - if (isConnectionError(err)) { - connection.close().catch(function (err) {}); - connection.__knex__disposed = err; - } - resultSet.close(function () { - return cb(err); - }); - } else if (rows.length === 0) { - return cb(null, fetchResult); - } else if (rows.length > 0) { - if (rows.length === numRows) { - fetchResult.rows = fetchResult.rows.concat(rows); - fetchRowsFromRS(connection, resultSet, numRows); - } else { - fetchResult.rows = fetchResult.rows.concat(rows); - return cb(null, fetchResult); - } + connection.execute( + sql, + bindParams || [], + options, + function (err, result) { + if (err) { + if (isConnectionError(err)) { + connection.close().catch(function (err) {}); + connection.__knex__disposed = err; } - }); - }; - fetchRowsFromRS(connection, result.resultSet, numRows); - }); - } else { - connection.execute(sql, bindParams || [], options, function ( - err, - result - ) { - if (err) { - // dispose the connection on connection error - if (isConnectionError(err)) { - connection.close().catch(function (err) {}); - connection.__knex__disposed = err; + return cb(err); } - return cb(err); + const fetchResult = { rows: [], resultSet: result.resultSet }; + const numRows = 100; + const fetchRowsFromRS = function ( + connection, + resultSet, + numRows + ) { + resultSet.getRows(numRows, function (err, rows) { + if (err) { + if (isConnectionError(err)) { + connection.close().catch(function (err) {}); + connection.__knex__disposed = err; + } + resultSet.close(function () { + return cb(err); + }); + } else if (rows.length === 0) { + return cb(null, fetchResult); + } else if (rows.length > 0) { + if (rows.length === numRows) { + fetchResult.rows = fetchResult.rows.concat(rows); + fetchRowsFromRS(connection, resultSet, numRows); + } else { + fetchResult.rows = fetchResult.rows.concat(rows); + return cb(null, fetchResult); + } + } + }); + }; + fetchRowsFromRS(connection, result.resultSet, numRows); } + ); + } else { + connection.execute( + sql, + bindParams || [], + options, + function (err, result) { + if (err) { + // dispose the connection on connection error + if (isConnectionError(err)) { + connection.close().catch(function (err) {}); + connection.__knex__disposed = err; + } + return cb(err); + } - return cb(null, result); - }); + return cb(null, result); + } + ); } }); connection.executeAsync = function (sql, bindParams, options) {