Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/SqlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class SqlFormatter
);

// Punctuation that can be used as a boundary between other tokens
protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
const DEFAULT_BOUNDARIES = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v PHP 5.6 nemoze byt public const.

protected static $boundaries = self::DEFAULT_BOUNDARIES;

// For HTML syntax highlighting
// Styles applied to different token types
Expand Down Expand Up @@ -178,6 +179,12 @@ public static function getCacheStats()
);
}

public static function setBoundaries(array $boundaries)
{
self::$boundaries = $boundaries;
self::$regex_boundaries = '('.implode('|',array_map(array(__CLASS__, 'quote_regex'),self::$boundaries)).')';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pri zmene tychto vyhradenych znakov, je potrebne upravit aj regexp.

}

/**
* Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words.
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/SqlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function testCacheStats() {

public function testSynapseTempTables() {
// In Azure Synapse is # char reserved for temp tables, not for comments
SqlFormatter::setBoundaries(array_diff(SqlFormatter::DEFAULT_BOUNDARIES, ['#']));
SqlFormatter::$comment_tokens = [
['--'],
];
Expand All @@ -122,7 +123,7 @@ public function testSynapseTempTables() {
$sqlWithComment = "-- This is comment\n" . $sql;
$expected = <<<SQL
SELECT
* INTO # temp_table
* INTO #temp_table
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prehliadol som, ze mi to tu pridava medzeru, co je nespravne.

FROM
SOURCE_TABLE;
SQL;
Expand Down