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

Commit e9e5f9d1 by Sascha Depold

Merge pull request #297 from kbackowski/fix_empty_in_condition

Fixed IN statements to generate valid sql when condition array is empty
2 parents c37ecba2 9118a4e2
...@@ -340,7 +340,7 @@ module.exports = (function() { ...@@ -340,7 +340,7 @@ module.exports = (function() {
if (Array.isArray(value)) { if (Array.isArray(value)) {
// is value an array? // is value an array?
if(value.length == 0) { value = [null] }
_value = "(" + value.map(function(subValue) { _value = "(" + value.map(function(subValue) {
return Utils.escape(subValue); return Utils.escape(subValue);
}).join(',') + ")" }).join(',') + ")"
......
...@@ -407,6 +407,7 @@ module.exports = (function() { ...@@ -407,6 +407,7 @@ module.exports = (function() {
, _value = null , _value = null
if(Array.isArray(value)) { if(Array.isArray(value)) {
if(value.length == 0) { value = [null] }
_value = "(" + value.map(function(subValue) { _value = "(" + value.map(function(subValue) {
return pgEscape(subValue); return pgEscape(subValue);
}).join(',') + ")" }).join(',') + ")"
......
...@@ -207,6 +207,10 @@ describe('QueryGenerator', function() { ...@@ -207,6 +207,10 @@ describe('QueryGenerator', function() {
{ {
arguments: [{ id: [1,2,3] }], arguments: [{ id: [1,2,3] }],
expectation: "`id` IN (1,2,3)" expectation: "`id` IN (1,2,3)"
},
{
arguments: [{ id: [] }],
expectation: "`id` IN (NULL)"
} }
] ]
} }
......
...@@ -237,6 +237,10 @@ describe('QueryGenerator', function() { ...@@ -237,6 +237,10 @@ describe('QueryGenerator', function() {
{ {
arguments: [{ id: [1,2,3] }], arguments: [{ id: [1,2,3] }],
expectation: "\"id\" IN (1,2,3)" expectation: "\"id\" IN (1,2,3)"
},
{
arguments: [{ id: [] }],
expectation: "\"id\" IN (NULL)"
} }
] ]
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!