Skip to content

Ability to use existing database connection #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions lib/transports/idbTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ try {

function idbCall(config, xmlInput, cb) {
const {
existingConnection = null,
database = '*LOCAL',
username = null,
password = null,
Expand All @@ -40,24 +41,32 @@ 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);

if (typeof verbose === 'boolean') {
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);

Expand All @@ -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);
};
Expand Down
5 changes: 5 additions & 0 deletions lib/transports/odbcTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function odbcCall(config, xmlInput, done) {
xslib = 'QXMLSERV',
verbose = false,
dsn = null,
ccsid = null
} = config;

const sql = `call ${xslib}.iPLUGR512K(?,?,?)`;
Expand All @@ -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}`);
Expand Down