Skip to content

Commit 35c58c1

Browse files
committed
[odbcTransport] Update how a connection is obtained
The node-odbc updated the API and connections are no longer obtained through the Connection constructor. Instead a call to the connect function will return a connected Connection object.
1 parent c0e80ff commit 35c58c1

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

lib/transports/odbcTransport.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
function odbcCall(config, xmlInput, done) {
2020
// eslint-disable-next-line global-require
21-
const { Connection } = require('odbc');
21+
const odbc = require('odbc');
2222

2323
const {
2424
host = 'localhost',
@@ -52,39 +52,30 @@ function odbcCall(config, xmlInput, done) {
5252
console.log(`SQL to run is ${sql}`);
5353
}
5454

55-
let connection;
56-
57-
// potentially throws an error with invalid SYSTEM, UID, PWD
58-
try {
59-
connection = new Connection(connectionString);
60-
} catch (error) {
61-
done(error, null);
62-
}
63-
64-
connection.query(sql, [ipc, ctl, xmlInput], (queryError, results) => {
65-
if (queryError) {
66-
done(queryError, null);
67-
return;
68-
}
69-
70-
connection.close((closeError) => {
71-
if (closeError) {
72-
done(closeError, null);
55+
odbc.connect(connectionString, (connectError, connection) => {
56+
connection.query(sql, [ipc, ctl, xmlInput], (queryError, results) => {
57+
if (queryError) {
58+
done(queryError, null);
7359
return;
7460
}
75-
76-
if (!results) {
77-
done('Empty result set was returned', null);
78-
return;
79-
}
80-
81-
let xmlOutput = '';
82-
83-
results.forEach((chunk) => {
84-
xmlOutput += chunk.OUT151;
61+
connection.close((closeError) => {
62+
if (closeError) {
63+
done(closeError, null);
64+
return;
65+
}
66+
67+
if (!results) {
68+
done('Empty result set was returned', null);
69+
return;
70+
}
71+
72+
let xmlOutput = '';
73+
74+
results.forEach((chunk) => {
75+
xmlOutput += chunk.OUT151;
76+
});
77+
done(null, xmlOutput);
8578
});
86-
87-
done(null, xmlOutput);
8879
});
8980
});
9081
}

0 commit comments

Comments
 (0)