Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 8643d53

Browse files
committed
fix to registration problem related to invoking java bridge
1 parent 8028713 commit 8643d53

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

initializers/dataAccess.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,19 @@ function parameterizeQuery(query, params, callback) {
113113
});
114114
}
115115

116+
function isSafeToUseJavaBridge(sql) {
117+
var lowerSQL = sql.toLowerCase();
118+
return lowerSQL.indexOf("insert") === -1 && lowerSQL.indexOf("update") === -1 && lowerSQL.indexOf("delete") === -1;
119+
}
120+
116121
function executePreparedStatement(api, sql, parameters, connection, next, db) {
117122
async.waterfall([
118123
function (cb) {
119124
parameterizeQuery(sql, parameters, cb);
120125
}, function (parametrizedQuery, cb) {
121126
sql = parametrizedQuery;
122127

123-
if (api.helper.readTransaction) {
128+
if (isSafeToUseJavaBridge(sql) && api.helper.readTransaction) {
124129
api.log("Calling Java Bridge", "debug");
125130

126131
api.log(sql, "debug");
@@ -304,7 +309,9 @@ exports.dataAccess = function (api, next) {
304309
return;
305310
}
306311

307-
if (!api.helper.readTransaction) {
312+
sql = queries[queryName].sql;
313+
314+
if (!isSafeToUseJavaBridge(sql) || !api.helper.readTransaction) {
308315
connection = connectionMap[queries[queryName].db];
309316
error = helper.checkObject(connection, "connection");
310317
}
@@ -314,7 +321,6 @@ exports.dataAccess = function (api, next) {
314321
return;
315322
}
316323

317-
sql = queries[queryName].sql;
318324
if (!sql) {
319325
api.log('Unregistered query ' + queryName + ' is asked for.', 'error');
320326
next('The query for name ' + queryName + ' is not registered');
@@ -354,7 +360,7 @@ exports.dataAccess = function (api, next) {
354360
return;
355361
}
356362

357-
if (!api.helper.readTransaction) {
363+
if (!isSafeToUseJavaBridge(sql) || !api.helper.readTransaction) {
358364
connection = connectionMap[dbName];
359365
error = helper.checkObject(connection, "connection");
360366
}
@@ -368,4 +374,4 @@ exports.dataAccess = function (api, next) {
368374
}
369375
};
370376
next();
371-
};
377+
};

0 commit comments

Comments
 (0)