fix finding null values

This commit is contained in:
AJ ONeal 2016-03-22 21:22:58 +00:00
parent 91a59fa5ad
commit 8647faa5a9
1 changed files with 11 additions and 3 deletions

View File

@ -13,7 +13,12 @@ function wrap(db, dir, dbsMap) {
}
db.escape = function (str) {
return (str||'').toString().replace(/'/g, "''");
// TODO? literals for true,false,null
// error on undefined?
if (undefined === str) {
str = '';
}
return String(str).replace(/'/g, "''");
};
function lowerFirst(str) {
@ -233,11 +238,14 @@ function wrap(db, dir, dbsMap) {
sql += 'AND ';
}
if (null === obj[key]) {
sql += db.escape(snakeCase(key)) + " IS '" + db.escape(obj[key]) + "'";
sql += db.escape(snakeCase(key)) + " IS null";
}
else {
// TODO check that key is some type? ignore undefined?
if (undefined === obj[key]) {
sql += db.escape(snakeCase(key)) + " = '" + db.escape(obj[key]) + "'";
}
}
});
}
else if (null !== obj || (params && !params.limit)) {