From 8c24c9ae2caa97fddad66d693dd06d76d84d59f5 Mon Sep 17 00:00:00 2001 From: Eric Henson Date: Fri, 8 May 2020 16:33:47 -0500 Subject: [PATCH 1/4] added support for using an existing node-odbc connection Signed-off-by: Eric Henson --- lib/transports/odbcTransport.js | 57 +++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/lib/transports/odbcTransport.js b/lib/transports/odbcTransport.js index 46684a9d..595cf9fa 100644 --- a/lib/transports/odbcTransport.js +++ b/lib/transports/odbcTransport.js @@ -20,6 +20,7 @@ function odbcCall(config, xmlInput, done) { const odbc = require('odbc'); const { + odbcConnection = null, host = 'localhost', username = null, password = null, @@ -51,36 +52,52 @@ function odbcCall(config, xmlInput, done) { console.log(`SQL to run is ${sql}`); } - odbc.connect(connectionString, (connectError, connection) => { - if (connectError) { - done(connectError, null); + function processXml(results) { + if (!results) { + done('Empty result set was returned', null); return; } + + let xmlOutput = ''; + + results.forEach((chunk) => { + xmlOutput += chunk.OUT151; + }); + done(null, xmlOutput); + } + + function query(connection) { connection.query(sql, [ipc, ctl, xmlInput], (queryError, results) => { if (queryError) { done(queryError, null); return; } - connection.close((closeError) => { - if (closeError) { - done(closeError, null); - return; - } - - if (!results) { - done('Empty result set was returned', null); - return; - } + if (!odbcConnection) { + connection.close((closeError) => { + if (closeError) { + done(closeError, null); + return; + } - let xmlOutput = ''; - - results.forEach((chunk) => { - xmlOutput += chunk.OUT151; + processXml(results); }); - done(null, xmlOutput); - }); + } else { + processXml(results); + } }); - }); + } + + if (!odbcConnection) { + odbc.connect(connectionString, (connectError, connection) => { + if (connectError) { + done(connectError, null); + return; + } + query(connection); + }); + } else { + query(odbcConnection); + } } exports.odbcCall = odbcCall; From eac8aab2b4398a5c6f13c8a464b92ecc24da81a8 Mon Sep 17 00:00:00 2001 From: Eric Henson Date: Fri, 8 May 2020 16:50:56 -0500 Subject: [PATCH 2/4] Updated the odbcOptions jsDoc Signed-off-by: Eric Henson --- lib/Connection.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Connection.js b/lib/Connection.js index 490d3292..41768baa 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -37,6 +37,7 @@ const availableTransports = { * @property {string} [ipc=*NA] - The key name/security route to XMLSERVICE job. Default is ``*NA``. * @property {string} [ctl=*here] - The control options for XMLSERVICE jobs. Default is ``*here``. * @property {string} [xslib=QXMLSERV] - The XMLSERVICE library. Default is ``QXMLSERV``. + * @property {object} [odbcConnection] - An existing odbc connection. */ /** From 4e5a2f047a02e539cd88fff6ced4491fe97b54d9 Mon Sep 17 00:00:00 2001 From: Eric Henson Date: Fri, 8 May 2020 16:50:56 -0500 Subject: [PATCH 3/4] Updated the odbcOptions jsDoc Signed-off-by: Eric Henson --- lib/Connection.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Connection.js b/lib/Connection.js index 41768baa..54d836e8 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -49,6 +49,7 @@ const availableTransports = { * @property {string} [ipc=*NA] - The key name/security route to XMLSERVICE job. Default is ``*NA``. * @property {string} [ctl=*here] - The control options for XMLSERVICE jobs. Default is ``*here``. * @property {string} [xslib=QXMLSERV] - The XMLSERVICE library. Default is ``QXMLSERV``. + * @property {object} odbcConnection - An optional odbc connection instead of a creating a new one. */ /** From 700b8e7fa569ddc103a6bb51b9eaadcf0d9da17c Mon Sep 17 00:00:00 2001 From: Eric Henson Date: Sat, 9 May 2020 00:57:32 -0500 Subject: [PATCH 4/4] changed the function name from processXml to processResults Signed-off-by: Eric Henson --- lib/transports/odbcTransport.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/transports/odbcTransport.js b/lib/transports/odbcTransport.js index 595cf9fa..f48abb6b 100644 --- a/lib/transports/odbcTransport.js +++ b/lib/transports/odbcTransport.js @@ -52,7 +52,7 @@ function odbcCall(config, xmlInput, done) { console.log(`SQL to run is ${sql}`); } - function processXml(results) { + function processResults(results) { if (!results) { done('Empty result set was returned', null); return; @@ -79,10 +79,10 @@ function odbcCall(config, xmlInput, done) { return; } - processXml(results); + processResults(results); }); } else { - processXml(results); + processResults(results); } }); }