From de16826069aa012f42cb49e103ad818a5a5a2fa9 Mon Sep 17 00:00:00 2001 From: Liam Allan Date: Mon, 14 Dec 2020 17:23:19 -0500 Subject: [PATCH 1/2] Ability to use existing idb connection --- lib/transports/idbTransport.js | 39 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/transports/idbTransport.js b/lib/transports/idbTransport.js index e421a45..6c461e4 100644 --- a/lib/transports/idbTransport.js +++ b/lib/transports/idbTransport.js @@ -28,6 +28,7 @@ try { function idbCall(config, xmlInput, cb) { const { + existingConnection = null, database = '*LOCAL', username = null, password = null, @@ -40,7 +41,25 @@ function idbCall(config, xmlInput, cb) { let xmlOutput = ''; const sql = `call ${xslib}.iPLUGR512K(?,?,?)`; // eslint-disable-next-line new-cap - const conn = new idb.dbconn(); + let conn; + + if (existingConnection) { + //If the user passes in an existing connect, then we should use it. + conn = existingConnection; + + } else { + conn = new idb.dbconn(); + try { + if (username && password) { + conn.conn(database, username, password); + } else { + conn.conn(database); + } + } catch (error) { + cb(error, null); + return; + } + } conn.setConnAttr(idb.SQL_ATTR_DBC_SYS_NAMING, idb.SQL_FALSE); @@ -48,16 +67,6 @@ function idbCall(config, xmlInput, cb) { conn.debug(verbose); } - try { - if (username && password) { - conn.conn(database, username, password); - } else { - conn.conn(database); - } - } catch (error) { - cb(error, null); - return; - } // eslint-disable-next-line new-cap const stmt = new idb.dbstmt(conn); @@ -70,8 +79,12 @@ function idbCall(config, xmlInput, cb) { // Before returning to caller, we must clean up const done = (err, val) => { stmt.close(); - conn.disconn(); - conn.close(); + + //Do not destroy the connection passed in. + if (!existingConnection) { + conn.disconn(); + conn.close(); + } cb(err, val); }; From aea79faadf9427e27600e77cec64cd3b9dbcff60 Mon Sep 17 00:00:00 2001 From: barry <3708366+worksofliam@users.noreply.github.com> Date: Tue, 18 May 2021 15:52:51 -0400 Subject: [PATCH 2/2] Update odbcTransport.js --- lib/transports/odbcTransport.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/transports/odbcTransport.js b/lib/transports/odbcTransport.js index 7786a9f..acde9c2 100644 --- a/lib/transports/odbcTransport.js +++ b/lib/transports/odbcTransport.js @@ -36,6 +36,7 @@ function odbcCall(config, xmlInput, done) { xslib = 'QXMLSERV', verbose = false, dsn = null, + ccsid = null } = config; const sql = `call ${xslib}.iPLUGR512K(?,?,?)`; @@ -54,6 +55,10 @@ function odbcCall(config, xmlInput, done) { connectionString += `PWD=${password};`; } } + + if (ccsid) { + connectionString += `CCSID=${ccsid};`; + } if (verbose) { console.log(`SQL to run is ${sql}`);