Commit 0a7d5f0c authored by Bruno's avatar Bruno Committed by Bruno Vitorino

Include statements that contain the ARRAY[] notation

The first capturing group of the parser regex was stopping form the moment it would find a `[` character.
parent ff30f9aa
...@@ -14,6 +14,7 @@ use function is_int; ...@@ -14,6 +14,7 @@ use function is_int;
use function key; use function key;
use function ksort; use function ksort;
use function preg_match_all; use function preg_match_all;
use function sprintf;
use function strlen; use function strlen;
use function strpos; use function strpos;
use function substr; use function substr;
...@@ -203,7 +204,9 @@ class SQLParserUtils ...@@ -203,7 +204,9 @@ class SQLParserUtils
self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' . self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' .
self::ESCAPED_BACKTICK_QUOTED_TEXT . '|' . self::ESCAPED_BACKTICK_QUOTED_TEXT . '|' .
self::ESCAPED_BRACKET_QUOTED_TEXT; self::ESCAPED_BRACKET_QUOTED_TEXT;
preg_match_all('/([^\'"`\[]+)(?:' . $literal . ')?/s', $statement, $fragments, PREG_OFFSET_CAPTURE); $expression = sprintf('/((.+(?i:ARRAY)\\[.+\\])|([^\'"`\\[]+))(?:%s)?/s', $literal);
preg_match_all($expression, $statement, $fragments, PREG_OFFSET_CAPTURE);
return $fragments[1]; return $fragments[1];
} }
......
...@@ -59,6 +59,10 @@ class SQLParserUtilsTest extends DbalTestCase ...@@ -59,6 +59,10 @@ class SQLParserUtilsTest extends DbalTestCase
['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552
['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295
['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']],
['SELECT table.field1, ARRAY[\'3\'] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']', false, [73 => 'foo']],
['SELECT table.field1, ARRAY[\'3\']::integer[] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']::integer[]', false, [84 => 'foo']],
['SELECT table.field1, ARRAY[:foo] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']', false, [27 => 'foo', 74 => 'bar']],
['SELECT table.field1, ARRAY[:foo]::integer[] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']::integer[]', false, [27 => 'foo', 85 => 'bar']],
[ [
<<<'SQLDATA' <<<'SQLDATA'
SELECT * FROM foo WHERE SELECT * FROM foo WHERE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment