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

Commit 3b35dc9f by Sushant Committed by Mick Hansen

Fix #5736, Invalid query generated when using LIKE with ANY (#5840)

* added failing test case for LIKE ANY parentheses issue

* wrap ANY arguments with parentheses when using LIKE + ANY

* changelog entry for #5736
1 parent e1b5ab5d
# Future # Future
- [FIXED] Invalid query generated when using LIKE + ANY [#5736](https://github.com/sequelize/sequelize/issues/5736)
- [FIXED] Method QueryInterface.bulkDelete no longer working when the model parameter is missing. (PostgreSQL) [#5615](https://github.com/sequelize/sequelize/issues/5615) - [FIXED] Method QueryInterface.bulkDelete no longer working when the model parameter is missing. (PostgreSQL) [#5615](https://github.com/sequelize/sequelize/issues/5615)
- [ADDED] Context and custom options for deep creation - [ADDED] Context and custom options for deep creation
......
...@@ -2240,6 +2240,11 @@ var QueryGenerator = { ...@@ -2240,6 +2240,11 @@ var QueryGenerator = {
if (escapeValue) { if (escapeValue) {
value = this.escape(value, field, escapeOptions); value = this.escape(value, field, escapeOptions);
//if ANY is used with like, add parentheses to generate correct query
if (escapeOptions.acceptStrings && (comparator.indexOf('ANY') > comparator.indexOf('LIKE'))) {
value = '(' + value + ')';
}
} }
} }
......
...@@ -572,7 +572,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -572,7 +572,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
$any: ['foo', 'bar', 'baz'] $any: ['foo', 'bar', 'baz']
} }
}, { }, {
postgres: "\"userId\" LIKE ANY ARRAY['foo','bar','baz']" postgres: "\"userId\" LIKE ANY (ARRAY['foo','bar','baz'])"
}); });
testsql('userId', { testsql('userId', {
...@@ -580,7 +580,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -580,7 +580,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
$any: ['foo', 'bar', 'baz'] $any: ['foo', 'bar', 'baz']
} }
}, { }, {
postgres: "\"userId\" ILIKE ANY ARRAY['foo','bar','baz']" postgres: "\"userId\" ILIKE ANY (ARRAY['foo','bar','baz'])"
}); });
testsql('userId', { testsql('userId', {
...@@ -588,7 +588,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -588,7 +588,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
$any: ['foo', 'bar', 'baz'] $any: ['foo', 'bar', 'baz']
} }
}, { }, {
postgres: "\"userId\" NOT LIKE ANY ARRAY['foo','bar','baz']" postgres: "\"userId\" NOT LIKE ANY (ARRAY['foo','bar','baz'])"
}); });
testsql('userId', { testsql('userId', {
...@@ -596,7 +596,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -596,7 +596,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
$any: ['foo', 'bar', 'baz'] $any: ['foo', 'bar', 'baz']
} }
}, { }, {
postgres: "\"userId\" NOT ILIKE ANY ARRAY['foo','bar','baz']" postgres: "\"userId\" NOT ILIKE ANY (ARRAY['foo','bar','baz'])"
}); });
testsql('userId', { testsql('userId', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!