Permalink
Browse files

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

sqlite backend produce invalid sql if value is 'undefined'
  • Loading branch information...
2 parents f47d000 + 9975632 commit a2a07c2e0ca1c622e3c11f50354d72674cc2f1ae @sdepold committed Jun 11, 2012
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/dialects/sqlite/query-generator.js
  2. +12 −0 spec-jasmine/sqlite/query-generator.spec.js
View
2 lib/dialects/sqlite/query-generator.js
@@ -4,7 +4,7 @@ var Utils = require("../../utils")
var escape = function(str) {
if (typeof str === 'string') {
return "'" + str.replace(/'/g, "''") + "'"
- } else if(str === null) {
+ } else if(str === null || str === undefined) {
return 'NULL'
} else {
return str
View
12 spec-jasmine/sqlite/query-generator.spec.js
@@ -16,6 +16,12 @@ describe('QueryGenerator', function() {
}, {
arguments: ['myTable', { name: "'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() {
}, {
arguments: ['myTable', { name: "'bar'" }, { 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"
}
]
};

0 comments on commit a2a07c2

Please sign in to comment.