不要怂,就是干,撸起袖子干!

Commit a2a07c2e by Sascha Depold

Merge pull request #185 from vlmonk/undefined-value-bug

sqlite backend produce invalid sql if value is 'undefined'
2 parents f47d000c 99756325
...@@ -4,7 +4,7 @@ var Utils = require("../../utils") ...@@ -4,7 +4,7 @@ var Utils = require("../../utils")
var escape = function(str) { var escape = function(str) {
if (typeof str === 'string') { if (typeof str === 'string') {
return "'" + str.replace(/'/g, "''") + "'" return "'" + str.replace(/'/g, "''") + "'"
} else if(str === null) { } else if(str === null || str === undefined) {
return 'NULL' return 'NULL'
} else { } else {
return str return str
......
...@@ -16,6 +16,12 @@ describe('QueryGenerator', function() { ...@@ -16,6 +16,12 @@ describe('QueryGenerator', function() {
}, { }, {
arguments: ['myTable', { name: "'bar'" }], arguments: ['myTable', { name: "'bar'" }],
expectation: "INSERT INTO `myTable` (`name`) VALUES ('''bar''');" expectation: "INSERT INTO `myTable` (`name`) VALUES ('''bar''');"
}, {
arguments: ['myTable', { name: "bar", value: null }],
expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('bar',NULL);"
}, {
arguments: ['myTable', { name: "bar", value: undefined }],
expectation: "INSERT INTO `myTable` (`name`,`value`) VALUES ('bar',NULL);"
} }
], ],
...@@ -26,6 +32,12 @@ describe('QueryGenerator', function() { ...@@ -26,6 +32,12 @@ describe('QueryGenerator', function() {
}, { }, {
arguments: ['myTable', { name: "'bar'" }, { id: 2 }], arguments: ['myTable', { name: "'bar'" }, { id: 2 }],
expectation: "UPDATE `myTable` SET `name`='''bar''' WHERE `id`=2" expectation: "UPDATE `myTable` SET `name`='''bar''' WHERE `id`=2"
}, {
arguments: ['myTable', { name: 'bar', value: null }, { id: 2 }],
expectation: "UPDATE `myTable` SET `name`='bar',`value`=NULL WHERE `id`=2"
}, {
arguments: ['myTable', { name: 'bar', value: undefined }, { id: 2 }],
expectation: "UPDATE `myTable` SET `name`='bar',`value`=NULL WHERE `id`=2"
} }
] ]
}; };
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!