@@ -113,14 +113,19 @@ function parameterizeQuery(query, params, callback) {
113
113
} ) ;
114
114
}
115
115
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
+
116
121
function executePreparedStatement ( api , sql , parameters , connection , next , db ) {
117
122
async . waterfall ( [
118
123
function ( cb ) {
119
124
parameterizeQuery ( sql , parameters , cb ) ;
120
125
} , function ( parametrizedQuery , cb ) {
121
126
sql = parametrizedQuery ;
122
127
123
- if ( api . helper . readTransaction ) {
128
+ if ( isSafeToUseJavaBridge ( sql ) && api . helper . readTransaction ) {
124
129
api . log ( "Calling Java Bridge" , "debug" ) ;
125
130
126
131
api . log ( sql , "debug" ) ;
@@ -304,7 +309,9 @@ exports.dataAccess = function (api, next) {
304
309
return ;
305
310
}
306
311
307
- if ( ! api . helper . readTransaction ) {
312
+ sql = queries [ queryName ] . sql ;
313
+
314
+ if ( ! isSafeToUseJavaBridge ( sql ) || ! api . helper . readTransaction ) {
308
315
connection = connectionMap [ queries [ queryName ] . db ] ;
309
316
error = helper . checkObject ( connection , "connection" ) ;
310
317
}
@@ -314,7 +321,6 @@ exports.dataAccess = function (api, next) {
314
321
return ;
315
322
}
316
323
317
- sql = queries [ queryName ] . sql ;
318
324
if ( ! sql ) {
319
325
api . log ( 'Unregistered query ' + queryName + ' is asked for.' , 'error' ) ;
320
326
next ( 'The query for name ' + queryName + ' is not registered' ) ;
@@ -354,7 +360,7 @@ exports.dataAccess = function (api, next) {
354
360
return ;
355
361
}
356
362
357
- if ( ! api . helper . readTransaction ) {
363
+ if ( ! isSafeToUseJavaBridge ( sql ) || ! api . helper . readTransaction ) {
358
364
connection = connectionMap [ dbName ] ;
359
365
error = helper . checkObject ( connection , "connection" ) ;
360
366
}
@@ -368,4 +374,4 @@ exports.dataAccess = function (api, next) {
368
374
}
369
375
} ;
370
376
next ( ) ;
371
- } ;
377
+ } ;
0 commit comments