Skip to content

Commit

Permalink
Allow undefined values in CQL query args and translate them to NULL
Browse files Browse the repository at this point in the history
Rather than checking for undefined values in the args array, check that the index exists, and treat undefined values as nulls.

Signed-off-by: Daniel Smedegaard Buus <[email protected]>
  • Loading branch information
DanielSmedegaardBuus committed Jan 10, 2014
1 parent fee9ccf commit 47eea4f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var queryParser = (function() {

var q = 0;
var a = 0;
var len = args.length;
var str = '';

try {
Expand All @@ -108,7 +109,7 @@ var queryParser = (function() {
q = query.indexOf('?', q);
if (q >= 0) {
str += query.substr(oldq, q-oldq);
if (args[a] === undefined) {
if (a >= len) {
throw new QueryParserError('Query parameter number ' + (a+1) + ' is not defined. Placeholder for not provided argument.');
}
str += typeEncoder.stringifyValue(args[a++]);
Expand Down Expand Up @@ -503,7 +504,7 @@ var typeEncoder = (function(){
* Converts a value to string for a query
*/
function stringifyValue (item) {
if (item === null) {
if (item === null || item === undefined) {
return 'NULL';
}
var value = item;
Expand All @@ -518,7 +519,7 @@ var typeEncoder = (function(){
subtype = typeInfo.subtype;
}
}
if (value === null) {
if (value === null || value === undefined) {
return 'NULL';
}
if (!type) {
Expand Down

0 comments on commit 47eea4f

Please sign in to comment.