From 8647faa5a9208f17a31bf2161cdd9413c4c9021c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 22 Mar 2016 21:22:58 +0000 Subject: [PATCH] fix finding null values --- lib/dbwrap.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/dbwrap.js b/lib/dbwrap.js index cc67861..3e09731 100644 --- a/lib/dbwrap.js +++ b/lib/dbwrap.js @@ -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,10 +238,13 @@ 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 { - sql += db.escape(snakeCase(key)) + " = '" + db.escape(obj[key]) + "'"; + // TODO check that key is some type? ignore undefined? + if (undefined === obj[key]) { + sql += db.escape(snakeCase(key)) + " = '" + db.escape(obj[key]) + "'"; + } } }); }