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]) + "'"; + } } }); }