From 91116f32dbe5f102592a884092ac19654ecbc1f4 Mon Sep 17 00:00:00 2001 From: Marat Dyatko Date: Sat, 8 Mar 2014 19:44:49 +0100 Subject: [PATCH] Prevent inserting undefined values The following SQL query was executed: INSERT INTO `cv` (`first_name`, `last_name`, `father_name`, `city`, `district`, `transfer`, `nationality`, `email`, `icq`, `skype`, `birth_date`, `marital_status`, `gender`, `children_status`, `id`) VALUES ('asdsd', , , '', '', , , 'i@marat.by', , , , , , , 2) ON DUPLICATE KEY UPDATE `first_name` = 'asdsd', `last_name` = undefined, `father_name` = undefined, `city` = '', `district` = '', `transfer` = undefined, `nationality` = undefined, `email` = 'i@marat.by', `icq` = undefined, `skype` = undefined, `birth_date` = undefined, `marital_status` = undefined, `gender` = undefined, `children_status` = undefined; --- lib/mysql.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 3c4831e..8ef3247 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -215,9 +215,13 @@ MySQL.prototype.updateOrCreate = function (model, data, callback) { } else { v = data[key]; } - fieldsNames.push(k); - fieldValues.push(v); - if (!mysql.id(model, key)) combined.push(k + ' = ' + v); + if (v !== undefined) { + fieldsNames.push(k); + fieldValues.push(v); + if (!mysql.id(model, key)) { + combined.push(k + ' = ' + v); + } + } } });