@@ -19,21 +19,21 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @var array |
| 21 | 21 | */ |
| 22 | - private $degenerations=[]; |
|
| 22 | + private $degenerations = []; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Query constructor. |
| 26 | 26 | * @param $sql |
| 27 | 27 | * @param array $degenerations |
| 28 | 28 | */ |
| 29 | - public function __construct($sql,$degenerations=[]) |
|
| 29 | + public function __construct($sql, $degenerations = []) |
|
| 30 | 30 | { |
| 31 | 31 | if (!trim($sql)) |
| 32 | 32 | { |
| 33 | 33 | throw new QueryException('Empty Query'); |
| 34 | 34 | } |
| 35 | 35 | $this->sql = $sql; |
| 36 | - $this->degenerations=$degenerations; |
|
| 36 | + $this->degenerations = $degenerations; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | // FORMAT\s(\w)*$ |
| 51 | 51 | if (null === $this->format) return false; |
| 52 | - $supportFormats= |
|
| 52 | + $supportFormats = |
|
| 53 | 53 | "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated"; |
| 54 | 54 | |
| 55 | - $matches=[]; |
|
| 56 | - if (preg_match_all('%('.$supportFormats.')%ius',$this->sql,$matches)){ |
|
| 55 | + $matches = []; |
|
| 56 | + if (preg_match_all('%(' . $supportFormats . ')%ius', $this->sql, $matches)) { |
|
| 57 | 57 | |
| 58 | 58 | // skip add "format json" |
| 59 | 59 | if (isset($matches[0])) |
| 60 | 60 | { |
| 61 | - $format=trim(str_ireplace('format','',$matches[0][0])); |
|
| 62 | - $this->format=$format; |
|
| 61 | + $format = trim(str_ireplace('format', '', $matches[0][0])); |
|
| 62 | + $this->format = $format; |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | foreach ($this->degenerations as $degeneration) |
| 94 | 94 | { |
| 95 | - if ($degeneration instanceof \ClickHouseDB\Query\Degeneration){ |
|
| 96 | - $this->sql=$degeneration->process($this->sql); |
|
| 95 | + if ($degeneration instanceof \ClickHouseDB\Query\Degeneration) { |
|
| 96 | + $this->sql = $degeneration->process($this->sql); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -48,7 +48,9 @@ discard block |
||
| 48 | 48 | private function applyFormatQuery() |
| 49 | 49 | { |
| 50 | 50 | // FORMAT\s(\w)*$ |
| 51 | - if (null === $this->format) return false; |
|
| 51 | + if (null === $this->format) { |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 52 | 54 | $supportFormats= |
| 53 | 55 | "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated"; |
| 54 | 56 | |
@@ -62,8 +64,7 @@ discard block |
||
| 62 | 64 | $this->format=$format; |
| 63 | 65 | |
| 64 | 66 | } |
| 65 | - } |
|
| 66 | - else { |
|
| 67 | + } else { |
|
| 67 | 68 | $this->sql = $this->sql . ' FORMAT ' . $this->format; |
| 68 | 69 | } |
| 69 | 70 | |