Skip to content

Commit 8fe00f0

Browse files
committed
Informix connection handling
1 parent 8192c76 commit 8fe00f0

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/common/informixHelper.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const helper = require('./helper')
77
const informix = require('informixdb')
88
const ReviewService = require('../services/ReviewService')
99
const ReviewSummationService = require('../services/ReviewSummationService')
10+
11+
let dbConnection = null
1012
/*
1113
* This function loads the online review details for a given submission from Informix.
1214
* It uses the data to create review and reviewSummation objects which are then saved
@@ -90,22 +92,26 @@ async function loadOnlineReviewDetails (authUser, submission) {
9092
}
9193

9294
function queryInformix (query) {
93-
const connectionString = 'SERVER=' + config.get('INFORMIX.SERVER') +
94-
';DATABASE=' + config.get('INFORMIX.DATABASE') +
95-
';HOST=' + config.get('INFORMIX.HOST') +
96-
';Protocol=' + config.get('INFORMIX.PROTOCOL') +
97-
';SERVICE=' + config.get('INFORMIX.PORT') +
98-
';DB_LOCALE=' + config.get('INFORMIX.DB_LOCALE') +
99-
';UID=' + config.get('INFORMIX.USER') +
95+
if (!dbConnection || dbConnection.connected==false) {
96+
const connectionString = 'SERVER=' + config.get('INFORMIX.SERVER') +
97+
';DATABASE=' + config.get('INFORMIX.DATABASE') +
98+
';HOST=' + config.get('INFORMIX.HOST') +
99+
';Protocol=' + config.get('INFORMIX.PROTOCOL') +
100+
';SERVICE=' + config.get('INFORMIX.PORT') +
101+
';DB_LOCALE=' + config.get('INFORMIX.DB_LOCALE') +
102+
';UID=' + config.get('INFORMIX.USER') +
100103
';PWD=' + config.get('INFORMIX.PASSWORD')
101-
104+
try {
105+
const dbConnection = informix.openSync(connectionString)
106+
} catch (ex) {
107+
logger.error(`Informix connection error: ${ex}`)
108+
}
109+
}
102110
let result = null
103111
try {
104-
const conn = informix.openSync(connectionString)
105-
result = conn.querySync(query)
106-
conn.closeSync()
112+
result = dbConnection.querySync(query)
107113
} catch (ex) {
108-
logger.error(ex)
114+
logger.error(`Informix query error: ${ex}`)
109115
}
110116

111117
return result

0 commit comments

Comments
 (0)