diff --git a/README.md b/README.md index 8073f53..d41ffb5 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,8 @@ Different value types are escaped differently, here is how: the object. If the property's value is a function, it is skipped; if the property's value is an object, toString() is called on it and the returned value is used. -* `undefined` / `null` are converted to `NULL` +* JavaScript `null` is converted to MySQL `NULL` +* JavaScript `undefined` is converted to MySQL `DEFAULT` * `NaN` / `Infinity` are left as-is. MySQL does not support these, and trying to insert them as values will trigger MySQL errors until they implement support. diff --git a/lib/SqlString.js b/lib/SqlString.js index 4dbf8fc..666450c 100644 --- a/lib/SqlString.js +++ b/lib/SqlString.js @@ -31,10 +31,14 @@ SqlString.escapeId = function escapeId(val, forbidQualified) { }; SqlString.escape = function escape(val, stringifyObjects, timeZone) { - if (val === undefined || val === null) { + if (val === null) { return 'NULL'; } + if (val === undefined) { + return 'DEFAULT'; + } + switch (typeof val) { case 'boolean': return (val) ? 'true' : 'false'; case 'number': return val+''; diff --git a/test/unit/test-SqlString.js b/test/unit/test-SqlString.js index 7ac6358..c3102de 100644 --- a/test/unit/test-SqlString.js +++ b/test/unit/test-SqlString.js @@ -35,8 +35,8 @@ test('SqlString.escapeId', { }); test('SqlString.escape', { - 'undefined -> NULL': function() { - assert.equal(SqlString.escape(undefined), 'NULL'); + 'undefined -> DEFAULT': function() { + assert.equal(SqlString.escape(undefined), 'DEFAULT'); }, 'null -> NULL': function() { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy