-
Notifications
You must be signed in to change notification settings - Fork 122
Apply SQL highlighting even if string starts with parenthesis #385
Comments
SQL handling is a bit wonky atm, false-positive could mess-up colors further. We need to think if there is no collision with something other than queries. However you can use heredoc to do same thing: $sql = <<<SQL
(SELECT * FROM `foo`)
UNION
(SELECT * FROM `bar`)
SQL; It's not that compact, but such queries are multi-line anyway. Edit: |
Was not aware of that option, thank you. |
@sogerc1 From PHP 7.3 not anymore: https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes These are now allowed: if(true){
$sql = <<<SQL
(SELECT * FROM `foo`)
UNION
(SELECT * FROM `bar`)
SQL;
} else {
$sql = <<<SQL
(SELECT * FROM `foo`)
UNION
(SELECT * FROM `bar`)
SQL;
} |
@KapitanOczywisty nice, hopefully my servers will also have php 7.3 someday. Not very easy to upgrade a running project's servers especially in small companies. |
@sogerc1 longer you wait, you'll have bigger problems with migration. This might help with preparing project files: https://github.com/PHPCompatibility/PHPCompatibility |
This is a cool suggestion. I wonder what's preventing you from adding this master...KapitanOczywisty:php-sql-1 as a PR? It does seem to work. Also unfortunately usage of heredoc for SQL highlighting in some codebases I use have a PHPCS rule against it. I'd prefer to use a simple string opener (quote, double-quote) where possible and I believe I wouldn't be the only one feeling this way.
|
Heredocs are valid and proper feature of PHP, fact that someone don't want to use them is not sufficient to introduce another alternative way to mark SQL queries (pointing at
It wasn't tested and properly thought through |
Summary
When an SQL string starts with an open parenthesis, as used when doing UNION with LIMIT or ORDER BY applied to the individual SELECTs, the SQL highlighting doesn't apply.
Ideally the highlighter would detect and highlight the SQL even if the string begins with
(SELECT
The text was updated successfully, but these errors were encountered: