Skip to content

Commit

Permalink
Merge pull request #4 from keboola/webrouse-COM-570-fix-synapse-comme…
Browse files Browse the repository at this point in the history
…nts-2

Added method setBoundaries
  • Loading branch information
michaljurecko committed Dec 11, 2020
2 parents 0643d07 + f056764 commit 03c7561
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/SqlFormatter.php
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(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
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)).')';
}

/**
* 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
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
FROM
SOURCE_TABLE;
SQL;
Expand Down

0 comments on commit 03c7561

Please sign in to comment.