|
1 | 1 | /* jshint node: true */ |
2 | 2 | "use strict"; |
3 | | -var _ = require("lodash"); |
4 | 3 | var jinst = require("./jinst"); |
5 | 4 | var CallableStatement = require('./callablestatement'); |
6 | 5 | var PreparedStatement = require('./preparedstatement'); |
@@ -97,16 +96,7 @@ Connection.prototype.createStatement = function(arg1, arg2, arg3, callback) { |
97 | 96 | callback = args.pop(); |
98 | 97 |
|
99 | 98 | // Check arguments for validity, and return error if invalid |
100 | | - var invalidArgs = false; |
101 | | - _.forEach(args, function(arg) { |
102 | | - if (! _.isNumber(arg)) { |
103 | | - invalidArgs = true; |
104 | | - // Lodash break |
105 | | - return false; |
106 | | - } |
107 | | - }); |
108 | | - |
109 | | - if (invalidArgs) { |
| 99 | + if (! allType(args, 'number')) { |
110 | 100 | return callback(new Error("INVALID ARGUMENTS")); |
111 | 101 | } |
112 | 102 |
|
@@ -308,13 +298,9 @@ Connection.prototype.prepareCall = function(sql, rstype, rsconcurrency, rsholdab |
308 | 298 | }; |
309 | 299 |
|
310 | 300 | function allType(array, type) { |
311 | | - _.each(array, function(el) { |
312 | | - if (typeof el !== type) { |
313 | | - return false; |
314 | | - } |
| 301 | + return array.every(function(el) { |
| 302 | + return typeof el === type; |
315 | 303 | }); |
316 | | - |
317 | | - return true; |
318 | 304 | } |
319 | 305 |
|
320 | 306 | /** |
@@ -351,34 +337,13 @@ Connection.prototype.prepareStatement = function(sql, arg1, arg2, arg3, callback |
351 | 337 | // be numbers if given, except for the special case when the first |
352 | 338 | // of these arguments is an array and no other arguments are given. |
353 | 339 | // In this special case, the array must be a string or number array. |
354 | | - // |
355 | | - // NOTE: _.tail returns all but the first argument, so we are only |
356 | | - // processing arg1, arg2, and arg3; and not sql (or callback, which |
357 | | - // was already removed from the args array). |
358 | | - var invalidArgs = false; |
359 | | - _.forEach(_.tail(args), function(arg, idx) { |
360 | | - // Check for the special case where arg1 can be an array of strings or numbers |
361 | | - // if arg2 and arg3 are not given |
362 | | - if (idx === 0 && _.isArray(arg) && _.isUndefined(args[2]) && _.isUndefined(args[3])) { |
363 | | - if (! (allType(arg, 'string') || allType(arg, 'number'))) { |
364 | | - invalidArgs = true; |
365 | | - |
366 | | - // Lodash break |
367 | | - return false; |
368 | | - } |
369 | | - |
370 | | - // Lodash continue |
371 | | - return; |
372 | | - } |
373 | | - |
374 | | - // Other than the special case above, these args must be numbers |
375 | | - if (! _.isNumber(arg)) { |
376 | | - invalidArgs = true; |
377 | | - |
378 | | - // Lodash break |
379 | | - return false; |
380 | | - } |
381 | | - }); |
| 340 | + var invalidArgs; |
| 341 | + if (args.length === 2 && Array.isArray(args[1])) { |
| 342 | + invalidArgs = ! (allType(args[1], 'string') || allType(args[1], 'number')); |
| 343 | + } else { |
| 344 | + // args[0] is sql (callback was already removed from the args array) |
| 345 | + invalidArgs = ! allType(args.slice(1), 'number'); |
| 346 | + } |
382 | 347 |
|
383 | 348 | if (invalidArgs) { |
384 | 349 | return callback(new Error(errMsg)); |
@@ -414,11 +379,6 @@ Connection.prototype.rollback = function(savepoint, callback) { |
414 | 379 | // Pull the callback off the end of the arguments |
415 | 380 | callback = args.pop(); |
416 | 381 |
|
417 | | - // Check arguments for validity, and return error if invalid |
418 | | - // if (! _.isObject(args[0])) { |
419 | | - // return callback(new Error("INVALID ARGUMENTS")); |
420 | | - // } |
421 | | - |
422 | 382 | // Push a callback handler onto the arguments |
423 | 383 | args.push(function(err) { |
424 | 384 | if (err) { |
@@ -461,9 +421,9 @@ Connection.prototype.setClientInfo = function(props, name, value, callback) { |
461 | 421 |
|
462 | 422 | // Check arguments for validity, manipulate the args array appropriately, |
463 | 423 | // and return error if invalid |
464 | | - if (_.isObject(args[0]) && _.isUndefined(args[1]) && _.isUndefined(args[2])) { |
| 424 | + if (typeof args[0] === 'object' && args[0] !== null && args[1] === undefined && args[2] === undefined) { |
465 | 425 | // Do nothing |
466 | | - } else if (_.isNull(args[0]) && _.isString(args[1]) && _.isString(args[2])) { |
| 426 | + } else if (args[0] === null && typeof args[1] === 'string' && typeof args[2] === 'string') { |
467 | 427 | // Remove first argument (props) from args array |
468 | 428 | args.shift(); |
469 | 429 | } else { |
@@ -515,7 +475,7 @@ Connection.prototype.setSavepoint = function(name, callback) { |
515 | 475 | callback = args.pop(); |
516 | 476 |
|
517 | 477 | // Check arguments for validity, and return error if invalid |
518 | | - if (! (_.isUndefined(args[0]) || _.isString(args[0]))) { |
| 478 | + if (! (args[0] === undefined || typeof args[0] === 'string')) { |
519 | 479 | return callback(new Error("INVALID ARGUMENTS")); |
520 | 480 | } |
521 | 481 |
|
|
0 commit comments