diff options
author | Lairson Alencar <lerao@cin.ufpe.br> | 2013-09-16 01:17:32 -0300 |
---|---|---|
committer | Lairson Alencar <lerao@cin.ufpe.br> | 2013-09-16 01:17:32 -0300 |
commit | 7f862d76ef8105ae8e25e1f04a49d00e06d7fd26 (patch) | |
tree | f84ecadf71bd398a3ec03af70689fcf3d0e080dc | |
parent | 7045fde3163d5a4ea6ec32e409a7dcf00779e204 (diff) | |
download | sql-formatter-7f862d76ef8105ae8e25e1f04a49d00e06d7fd26.zip sql-formatter-7f862d76ef8105ae8e25e1f04a49d00e06d7fd26.tar.gz sql-formatter-7f862d76ef8105ae8e25e1f04a49d00e06d7fd26.tar.bz2 |
#34 - Added formatting to SQL LIMIT
The Formatting was added as suggested by leeoniya (issue #34).
-rw-r--r-- | lib/SqlFormatter.php | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php index 2a021ff..2f04763 100644 --- a/lib/SqlFormatter.php +++ b/lib/SqlFormatter.php @@ -610,11 +610,6 @@ class SqlFormatter } } - // Commas start a new line (unless within inline parentheses) - elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { - $newline = true; - } - // Top level reserved words start a new line and increase the special indent level elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) { $increase_special_indent = true; @@ -641,6 +636,23 @@ class SqlFormatter if (strpos($token[self::TOKEN_VALUE],' ')!==false || strpos($token[self::TOKEN_VALUE],"\n")!==false || strpos($token[self::TOKEN_VALUE],"\t")!==false) { $highlighted = preg_replace('/\s+/',' ',$highlighted); } + //if SQL 'LIMIT' clause, start variable to reset newline + if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { + $clause_limit = true; + } + } + + // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause) + elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { + //If the previous TOKEN_VALUE is 'LIMIT', resets new line + if ($clause_limit === true) { + $newline = false; + $clause_limit = false; + } + // All other cases of commas + else { + $newline = true; + } } // Newline reserved words start a new line |