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

Commit 9118a4e2 by kbackowski

Fixed IN statements to generate valid sql when condition array is empty

1 parent 1b5385ac
...@@ -317,7 +317,7 @@ module.exports = (function() { ...@@ -317,7 +317,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(',') + ")"
......
...@@ -398,6 +398,7 @@ module.exports = (function() { ...@@ -398,6 +398,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)"
} }
] ]
} }
......
...@@ -234,6 +234,10 @@ describe('QueryGenerator', function() { ...@@ -234,6 +234,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!