|
9 | 9 | * @copyright 2013 Jeremy Dorn |
10 | 10 | * @license http://opensource.org/licenses/MIT |
11 | 11 | * @link http://github.com/jdorn/sql-formatter |
12 | | - * @version 1.2.17 |
| 12 | + * @version 1.2.18 |
13 | 13 | */ |
14 | 14 | class SqlFormatter |
15 | 15 | { |
@@ -102,7 +102,7 @@ class SqlFormatter |
102 | 102 | ); |
103 | 103 |
|
104 | 104 | // Punctuation that can be used as a boundary between other tokens |
105 | | - protected static $boundaries = array(',', ';',':', ']', '[', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#'); |
| 105 | + protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#'); |
106 | 106 |
|
107 | 107 | // For HTML syntax highlighting |
108 | 108 | // Styles applied to different token types |
@@ -235,9 +235,9 @@ protected static function getNextToken($string, $previous = null) |
235 | 235 | } |
236 | 236 |
|
237 | 237 | // Quoted String |
238 | | - if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`') { |
| 238 | + if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`' || $string[0]==='[') { |
239 | 239 | $return = array( |
240 | | - self::TOKEN_TYPE => ($string[0]==='`'? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE), |
| 240 | + self::TOKEN_TYPE => (($string[0]==='`' || $string[0]==='[')? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE), |
241 | 241 | self::TOKEN_VALUE => self::getQuotedString($string) |
242 | 242 | ); |
243 | 243 |
|
@@ -335,9 +335,10 @@ protected static function getQuotedString($string) |
335 | 335 |
|
336 | 336 | // This checks for the following patterns: |
337 | 337 | // 1. backtick quoted string using `` to escape |
338 | | - // 2. double quoted string using "" or \" to escape |
339 | | - // 3. single quoted string using '' or \' to escape |
340 | | - if ( preg_match('/^(((`[^`]*($|`))+)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) { |
| 338 | + // 2. square bracket quoted string (SQL Server) using ]] to escape |
| 339 | + // 3. double quoted string using "" or \" to escape |
| 340 | + // 4. single quoted string using '' or \' to escape |
| 341 | + if ( preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) { |
341 | 342 | $ret = $matches[1]; |
342 | 343 | } |
343 | 344 |
|
|
0 commit comments