@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | $body = $this->response()->body(); |
| 150 | 150 | $error_no = $this->response()->error_no(); |
| 151 | - $error=$this->response()->error(); |
|
| 151 | + $error = $this->response()->error(); |
|
| 152 | 152 | |
| 153 | 153 | if (!$error_no && !$error) { |
| 154 | 154 | $parse = $this->parseErrorClickHouse($body); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | else { |
| 160 | 160 | $code = $this->response()->http_code(); |
| 161 | - $message = "HttpCode:" . $this->response()->http_code() . " ; ".$this->response()->error()." ;" . $body; |
|
| 161 | + $message = "HttpCode:" . $this->response()->http_code() . " ; " . $this->response()->error() . " ;" . $body; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | else { |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | return false; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least','statistics'] as $key) { |
|
| 215 | + foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least', 'statistics'] as $key) { |
|
| 216 | 216 | if (isset($this->_rawData[$key])) { |
| 217 | 217 | $this->{$key} = $this->_rawData[$key]; |
| 218 | 218 | } |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * @param bool $key |
| 326 | 326 | * @return array|mixed|null |
| 327 | 327 | */ |
| 328 | - public function statistics($key=false) |
|
| 328 | + public function statistics($key = false) |
|
| 329 | 329 | { |
| 330 | 330 | $this->init(); |
| 331 | 331 | if ($key) |
@@ -155,13 +155,11 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | if ($parse) { |
| 157 | 157 | throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']); |
| 158 | - } |
|
| 159 | - else { |
|
| 158 | + } else { |
|
| 160 | 159 | $code = $this->response()->http_code(); |
| 161 | 160 | $message = "HttpCode:" . $this->response()->http_code() . " ; ".$this->response()->error()." ;" . $body; |
| 162 | 161 | } |
| 163 | - } |
|
| 164 | - else { |
|
| 162 | + } else { |
|
| 165 | 163 | $code = $error_no; |
| 166 | 164 | $message = $this->response()->error(); |
| 167 | 165 | } |
@@ -330,8 +328,12 @@ discard block |
||
| 330 | 328 | $this->init(); |
| 331 | 329 | if ($key) |
| 332 | 330 | { |
| 333 | - if (!is_array($this->statistics)) return null; |
|
| 334 | - if (!isset($this->statistics[$key])) return null; |
|
| 331 | + if (!is_array($this->statistics)) { |
|
| 332 | + return null; |
|
| 333 | + } |
|
| 334 | + if (!isset($this->statistics[$key])) { |
|
| 335 | + return null; |
|
| 336 | + } |
|
| 335 | 337 | return $this->statistics[$key]; |
| 336 | 338 | } |
| 337 | 339 | return $this->statistics; |
@@ -373,8 +375,7 @@ discard block |
||
| 373 | 375 | if ($key) { |
| 374 | 376 | if (isset($this->array_data[0][$key])) { |
| 375 | 377 | return $this->array_data[0][$key]; |
| 376 | - } |
|
| 377 | - else { |
|
| 378 | + } else { |
|
| 378 | 379 | return null; |
| 379 | 380 | } |
| 380 | 381 | } |
@@ -464,16 +465,14 @@ discard block |
||
| 464 | 465 | { |
| 465 | 466 | if (is_array($path)) { |
| 466 | 467 | $keys = $path; |
| 467 | - } |
|
| 468 | - else { |
|
| 468 | + } else { |
|
| 469 | 469 | $args = func_get_args(); |
| 470 | 470 | array_shift($args); |
| 471 | 471 | |
| 472 | 472 | if (sizeof($args) < 2) { |
| 473 | 473 | $separator = '.'; |
| 474 | 474 | $keys = explode($separator, $path); |
| 475 | - } |
|
| 476 | - else { |
|
| 475 | + } else { |
|
| 477 | 476 | $keys = $args; |
| 478 | 477 | } |
| 479 | 478 | } |
@@ -485,8 +484,7 @@ discard block |
||
| 485 | 484 | |
| 486 | 485 | if (isset($arr[$key])) { |
| 487 | 486 | $val = $arr[$key]; |
| 488 | - } |
|
| 489 | - else { |
|
| 487 | + } else { |
|
| 490 | 488 | $val = $key; |
| 491 | 489 | } |
| 492 | 490 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | class StrictQuoteLine |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - private $preset=[ |
|
| 9 | + private $preset = [ |
|
| 10 | 10 | 'CSV'=>[ |
| 11 | 11 | 'EnclosureArray'=>'"', |
| 12 | 12 | 'EncodeEnclosure'=>'"', |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | 'TabEncode'=>true, |
| 33 | 33 | ], |
| 34 | 34 | ]; |
| 35 | - private $settings=[]; |
|
| 35 | + private $settings = []; |
|
| 36 | 36 | |
| 37 | 37 | public function __construct($format) |
| 38 | 38 | { |
| 39 | 39 | if (empty($this->preset[$format])) |
| 40 | 40 | { |
| 41 | - throw new QueryException("Unsupport format encode line:".$format); |
|
| 41 | + throw new QueryException("Unsupport format encode line:" . $format); |
|
| 42 | 42 | } |
| 43 | - $this->settings=$this->preset[$format]; |
|
| 43 | + $this->settings = $this->preset[$format]; |
|
| 44 | 44 | } |
| 45 | 45 | public function quoteRow($row) |
| 46 | 46 | { |
| 47 | - return implode($this->settings['Delimiter'],$this->quoteValue($row)); |
|
| 47 | + return implode($this->settings['Delimiter'], $this->quoteValue($row)); |
|
| 48 | 48 | } |
| 49 | 49 | public function quoteValue($row) |
| 50 | 50 | { |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | $encode = $this->settings['EncodeEnclosure']; |
| 54 | 54 | $encodeArray = $this->settings['EnclosureArray']; |
| 55 | 55 | $null = $this->settings['Null']; |
| 56 | - $tabEncode=$this->settings['TabEncode']; |
|
| 56 | + $tabEncode = $this->settings['TabEncode']; |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - $quote = function ($value) use ($enclosure,$delimiter,$encode,$encodeArray,$null,$tabEncode) { |
|
| 59 | + $quote = function($value) use ($enclosure, $delimiter, $encode, $encodeArray, $null, $tabEncode) { |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | if (is_string($value)) { |
| 76 | 76 | if ($tabEncode) |
| 77 | 77 | { |
| 78 | - return str_replace(["\t","\n"],['\\t','\\n'],$value); |
|
| 78 | + return str_replace(["\t", "\n"], ['\\t', '\\n'], $value); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $value = strval($value); |
| 82 | - $value = preg_replace('/('.$enclosure_esc.'|'.$encode_esc.')/',$encode_esc.'\1', $value); |
|
| 82 | + $value = preg_replace('/(' . $enclosure_esc . '|' . $encode_esc . ')/', $encode_esc . '\1', $value); |
|
| 83 | 83 | return $enclosure . $value . $enclosure; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | // as in the TabSeparated format, and then the resulting string is output in InsertRow in double quotes. |
| 91 | 91 | $result_array = FormatLine::Insert($value); |
| 92 | 92 | |
| 93 | - return $encodeArray . '[' . $result_array . ']' .$encodeArray; |
|
| 93 | + return $encodeArray . '[' . $result_array . ']' . $encodeArray; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | if (null === $value) { |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | * @var array |
| 10 | 10 | */ |
| 11 | - private static $strict=[]; |
|
| 11 | + private static $strict = []; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Format |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | if (empty(self::$strict[$format])) |
| 22 | 22 | { |
| 23 | - self::$strict[$format]=new StrictQuoteLine($format); |
|
| 23 | + self::$strict[$format] = new StrictQuoteLine($format); |
|
| 24 | 24 | } |
| 25 | 25 | return self::$strict[$format]; |
| 26 | 26 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | } |
| 61 | 61 | if ($format) |
| 62 | 62 | { |
| 63 | - $this->setFormat($format); |
|
| 63 | + $this->setFormat($format); |
|
| 64 | 64 | } |
| 65 | 65 | $this->file_name=$file_name; |
| 66 | 66 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | const FORMAT_TabSeparatedWithNames = 'TabSeparatedWithNames'; |
| 14 | 14 | const FORMAT_CSV = 'CSV'; |
| 15 | 15 | |
| 16 | - private $support_format=['TabSeparated','TabSeparatedWithNames','CSV']; |
|
| 16 | + private $support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV']; |
|
| 17 | 17 | /** |
| 18 | 18 | * @var string |
| 19 | 19 | */ |
@@ -22,19 +22,19 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @var string |
| 24 | 24 | */ |
| 25 | - private $format='CSV'; |
|
| 25 | + private $format = 'CSV'; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @var bool |
| 29 | 29 | */ |
| 30 | - private $gzip=false; |
|
| 30 | + private $gzip = false; |
|
| 31 | 31 | /** |
| 32 | 32 | * WriteToFile constructor. |
| 33 | 33 | * @param $file_name |
| 34 | 34 | * @param bool $overwrite |
| 35 | 35 | * @param null $format |
| 36 | 36 | */ |
| 37 | - public function __construct($file_name,$overwrite=true,$format=null) { |
|
| 37 | + public function __construct($file_name, $overwrite = true, $format = null) { |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | if (!$file_name) |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | throw new QueryException('Can`t delete: ' . $file_name); |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | - $dir=dirname($file_name); |
|
| 56 | + $dir = dirname($file_name); |
|
| 57 | 57 | if (!is_writable($dir)) |
| 58 | 58 | { |
| 59 | 59 | throw new QueryException('Can`t writable dir: ' . $dir); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $this->setFormat($format); |
| 64 | 64 | } |
| 65 | - $this->file_name=$file_name; |
|
| 65 | + $this->file_name = $file_name; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function setGzip($flag) |
| 80 | 80 | { |
| 81 | - $this->gzip=$flag; |
|
| 81 | + $this->gzip = $flag; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function setFormat($format) |
| 88 | 88 | { |
| 89 | - if (!in_array($format,$this->support_format)) |
|
| 89 | + if (!in_array($format, $this->support_format)) |
|
| 90 | 90 | { |
| 91 | 91 | throw new QueryException('Unsupport format: ' . $format); |
| 92 | 92 | } |
| 93 | - $this->format=$format; |
|
| 93 | + $this->format = $format; |
|
| 94 | 94 | } |
| 95 | 95 | /** |
| 96 | 96 | * @return int |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function bindParams(array $bindings) |
| 15 | 15 | { |
| 16 | - $this->bindings=[]; |
|
| 16 | + $this->bindings = []; |
|
| 17 | 17 | foreach ($bindings as $column => $value) { |
| 18 | 18 | $this->bindParam($column, $value); |
| 19 | 19 | } |
@@ -17,44 +17,44 @@ discard block |
||
| 17 | 17 | public function bindParams(array $bindings) |
| 18 | 18 | { |
| 19 | 19 | foreach ($bindings as $column => $value) { |
| 20 | - $this->bindings[$column]=$value; |
|
| 20 | + $this->bindings[$column] = $value; |
|
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - static function __ifsets($matches,$markers,$else=false) |
|
| 25 | + static function __ifsets($matches, $markers, $else = false) |
|
| 26 | 26 | { |
| 27 | - $content_false=''; |
|
| 27 | + $content_false = ''; |
|
| 28 | 28 | |
| 29 | 29 | if ($else) |
| 30 | 30 | { |
| 31 | - list($condition, $preset ,$variable, $content_true, $content_false) = $matches; |
|
| 31 | + list($condition, $preset, $variable, $content_true, $content_false) = $matches; |
|
| 32 | 32 | } |
| 33 | 33 | else |
| 34 | 34 | { |
| 35 | - list($condition, $preset ,$variable, $content_true) = $matches; |
|
| 35 | + list($condition, $preset, $variable, $content_true) = $matches; |
|
| 36 | 36 | } |
| 37 | - $preset=strtolower($preset); |
|
| 37 | + $preset = strtolower($preset); |
|
| 38 | 38 | |
| 39 | - if ($preset=='set') |
|
| 39 | + if ($preset == 'set') |
|
| 40 | 40 | { |
| 41 | - return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true: $content_false; |
|
| 41 | + return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true : $content_false; |
|
| 42 | 42 | } |
| 43 | - if ($preset=='bool') |
|
| 43 | + if ($preset == 'bool') |
|
| 44 | 44 | { |
| 45 | - return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable]==true) |
|
| 45 | + return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable] == true) |
|
| 46 | 46 | ? $content_true |
| 47 | 47 | : $content_false; |
| 48 | 48 | } |
| 49 | - if ($preset=='string') |
|
| 49 | + if ($preset == 'string') |
|
| 50 | 50 | { |
| 51 | 51 | return (isset($markers[$variable]) && is_string($markers[$variable]) && strlen($markers[$variable])) |
| 52 | 52 | ? $content_true |
| 53 | 53 | : $content_false; |
| 54 | 54 | } |
| 55 | - if ($preset=='int') |
|
| 55 | + if ($preset == 'int') |
|
| 56 | 56 | { |
| 57 | - return (isset($markers[$variable]) && intval($markers[$variable])<>0 ) |
|
| 57 | + return (isset($markers[$variable]) && intval($markers[$variable]) <> 0) |
|
| 58 | 58 | ? $content_true |
| 59 | 59 | : $content_false; |
| 60 | 60 | } |
@@ -68,29 +68,29 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function process($sql) |
| 70 | 70 | { |
| 71 | - $markers=$this->bindings; |
|
| 71 | + $markers = $this->bindings; |
|
| 72 | 72 | |
| 73 | 73 | // 2. process if/else conditions |
| 74 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
| 74 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
| 75 | 75 | list($condition, $variable, $content_true, $content_false) = $matches; |
| 76 | 76 | |
| 77 | - return (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) ) ) |
|
| 77 | + return (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) |
|
| 78 | 78 | ? $content_true |
| 79 | 79 | : $content_false; |
| 80 | 80 | }, $sql); |
| 81 | 81 | |
| 82 | 82 | // 3. process if conditions |
| 83 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
| 83 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
| 84 | 84 | list($condition, $variable, $content) = $matches; |
| 85 | 85 | |
| 86 | - if (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) )) { |
|
| 86 | + if (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) { |
|
| 87 | 87 | return $content; |
| 88 | 88 | } |
| 89 | 89 | }, $sql); |
| 90 | 90 | |
| 91 | 91 | // 1. process if[set|int]/else conditions |
| 92 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) {return self::__ifsets($matches,$markers,true); }, $sql); |
|
| 93 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { return self::__ifsets($matches,$markers,false); }, $sql); |
|
| 92 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) {return self::__ifsets($matches, $markers, true); }, $sql); |
|
| 93 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { return self::__ifsets($matches, $markers, false); }, $sql); |
|
| 94 | 94 | |
| 95 | 95 | return $sql; |
| 96 | 96 | } |
@@ -29,8 +29,7 @@ |
||
| 29 | 29 | if ($else) |
| 30 | 30 | { |
| 31 | 31 | list($condition, $preset ,$variable, $content_true, $content_false) = $matches; |
| 32 | - } |
|
| 33 | - else |
|
| 32 | + } else |
|
| 34 | 33 | { |
| 35 | 34 | list($condition, $preset ,$variable, $content_true) = $matches; |
| 36 | 35 | } |
@@ -177,7 +177,7 @@ |
||
| 177 | 177 | */ |
| 178 | 178 | public function setTimeout($timeout) |
| 179 | 179 | { |
| 180 | - return $this->settings()->max_execution_time($timeout); |
|
| 180 | + return $this->settings()->max_execution_time($timeout); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -295,8 +295,7 @@ discard block |
||
| 295 | 295 | if (!$useSessionId) |
| 296 | 296 | { |
| 297 | 297 | $this->settings()->makeSessionId(); |
| 298 | - } |
|
| 299 | - else |
|
| 298 | + } else |
|
| 300 | 299 | { |
| 301 | 300 | $this->settings()->session_id($useSessionId); |
| 302 | 301 | } |
@@ -415,7 +414,9 @@ discard block |
||
| 415 | 414 | */ |
| 416 | 415 | public function progressFunction($callback) |
| 417 | 416 | { |
| 418 | - if (!is_callable($callback)) throw new \InvalidArgumentException('Not is_callable progressFunction'); |
|
| 417 | + if (!is_callable($callback)) { |
|
| 418 | + throw new \InvalidArgumentException('Not is_callable progressFunction'); |
|
| 419 | + } |
|
| 419 | 420 | |
| 420 | 421 | if (!$this->settings()->is('send_progress_in_http_headers')) |
| 421 | 422 | { |
@@ -540,7 +541,7 @@ discard block |
||
| 540 | 541 | } |
| 541 | 542 | $preparedValues[] = array_values($row); |
| 542 | 543 | } |
| 543 | - }else{ //одна строка |
|
| 544 | + } else{ //одна строка |
|
| 544 | 545 | $preparedFields = array_keys($values); |
| 545 | 546 | $preparedValues = [array_values($values)]; |
| 546 | 547 | } |
@@ -609,8 +610,7 @@ discard block |
||
| 609 | 610 | { |
| 610 | 611 | $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
| 611 | 612 | |
| 612 | - } |
|
| 613 | - else |
|
| 613 | + } else |
|
| 614 | 614 | { |
| 615 | 615 | $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
| 616 | 616 | |
@@ -654,8 +654,7 @@ discard block |
||
| 654 | 654 | { |
| 655 | 655 | $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
| 656 | 656 | |
| 657 | - } |
|
| 658 | - else |
|
| 657 | + } else |
|
| 659 | 658 | { |
| 660 | 659 | $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
| 661 | 660 | |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @var bool |
| 41 | 41 | */ |
| 42 | - private $_connect_user_readonly=false; |
|
| 42 | + private $_connect_user_readonly = false; |
|
| 43 | 43 | /** |
| 44 | 44 | * @var array |
| 45 | 45 | */ |
| 46 | - private $_support_format=['TabSeparated','TabSeparatedWithNames','CSV','CSVWithNames','JSONEachRow']; |
|
| 46 | + private $_support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV', 'CSVWithNames', 'JSONEachRow']; |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Client constructor. |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function setReadOnlyUser($flag) |
| 122 | 122 | { |
| 123 | - $this->_connect_user_readonly=$flag; |
|
| 123 | + $this->_connect_user_readonly = $flag; |
|
| 124 | 124 | $this->settings()->setReadOnlyUser($this->_connect_user_readonly); |
| 125 | 125 | } |
| 126 | 126 | /** |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | if (is_array($host)) |
| 165 | 165 | { |
| 166 | - $host=array_rand(array_flip($host)); |
|
| 166 | + $host = array_rand(array_flip($host)); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $this->_connect_host=$host; |
|
| 169 | + $this->_connect_host = $host; |
|
| 170 | 170 | $this->transport()->setHost($host); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | /** |
| 290 | 290 | * @return $this |
| 291 | 291 | */ |
| 292 | - public function useSession($useSessionId=false) |
|
| 292 | + public function useSession($useSessionId = false) |
|
| 293 | 293 | { |
| 294 | 294 | if (!$this->settings()->getSessionId()) |
| 295 | 295 | { |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | public function enableLogQueries($flag = true) |
| 348 | 348 | { |
| 349 | - $this->settings()->set('log_queries',intval($flag)); |
|
| 349 | + $this->settings()->set('log_queries', intval($flag)); |
|
| 350 | 350 | return $this; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @param bool $flag |
| 369 | 369 | * @return $this |
| 370 | 370 | */ |
| 371 | - public function https($flag=true) |
|
| 371 | + public function https($flag = true) |
|
| 372 | 372 | { |
| 373 | 373 | $this->settings()->https($flag); |
| 374 | 374 | return $this; |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | public function enableExtremes($flag = true) |
| 384 | 384 | { |
| 385 | - $this->settings()->set('extremes',intval($flag)); |
|
| 385 | + $this->settings()->set('extremes', intval($flag)); |
|
| 386 | 386 | return $this; |
| 387 | 387 | } |
| 388 | 388 | |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | * @throws Exception\TransportException |
| 398 | 398 | * @throws \Exception |
| 399 | 399 | */ |
| 400 | - public function select($sql, $bindings = [], $whereInFile = null, $writeToFile=null) |
|
| 400 | + public function select($sql, $bindings = [], $whereInFile = null, $writeToFile = null) |
|
| 401 | 401 | { |
| 402 | - return $this->transport()->select($sql, $bindings, $whereInFile,$writeToFile); |
|
| 402 | + return $this->transport()->select($sql, $bindings, $whereInFile, $writeToFile); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -445,9 +445,9 @@ discard block |
||
| 445 | 445 | * @throws Exception\TransportException |
| 446 | 446 | * @throws \Exception |
| 447 | 447 | */ |
| 448 | - public function selectAsync($sql, $bindings = [], $whereInFile = null,$writeToFile=null) |
|
| 448 | + public function selectAsync($sql, $bindings = [], $whereInFile = null, $writeToFile = null) |
|
| 449 | 449 | { |
| 450 | - return $this->transport()->selectAsync($sql, $bindings, $whereInFile,$writeToFile); |
|
| 450 | + return $this->transport()->selectAsync($sql, $bindings, $whereInFile, $writeToFile); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | */ |
| 485 | 485 | public function showCreateTable($table) |
| 486 | 486 | { |
| 487 | - return ($this->select('SHOW CREATE TABLE '.$table)->fetchOne('statement')); |
|
| 487 | + return ($this->select('SHOW CREATE TABLE ' . $table)->fetchOne('statement')); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -544,17 +544,17 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | public function prepareInsertAssocBulk(array $values) |
| 546 | 546 | { |
| 547 | - if (isset($values[0]) && is_array($values[0])){ //случай, когда много строк вставляется |
|
| 547 | + if (isset($values[0]) && is_array($values[0])) { //случай, когда много строк вставляется |
|
| 548 | 548 | $preparedFields = array_keys($values[0]); |
| 549 | 549 | $preparedValues = []; |
| 550 | - foreach ($values as $idx => $row){ |
|
| 550 | + foreach ($values as $idx => $row) { |
|
| 551 | 551 | $_fields = array_keys($row); |
| 552 | - if ($_fields !== $preparedFields){ |
|
| 553 | - throw new QueryException("Fields not match: ".implode(',',$_fields)." and ".implode(',', $preparedFields)." on element $idx"); |
|
| 552 | + if ($_fields !== $preparedFields) { |
|
| 553 | + throw new QueryException("Fields not match: " . implode(',', $_fields) . " and " . implode(',', $preparedFields) . " on element $idx"); |
|
| 554 | 554 | } |
| 555 | 555 | $preparedValues[] = array_values($row); |
| 556 | 556 | } |
| 557 | - }else{ //одна строка |
|
| 557 | + } else { //одна строка |
|
| 558 | 558 | $preparedFields = array_keys($values); |
| 559 | 559 | $preparedValues = [array_values($values)]; |
| 560 | 560 | } |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function insertBatchTSVFiles($table_name, $file_names, $columns_array) |
| 589 | 589 | { |
| 590 | - return $this->insertBatchFiles($table_name,$file_names,$columns_array,'TabSeparated'); |
|
| 590 | + return $this->insertBatchFiles($table_name, $file_names, $columns_array, 'TabSeparated'); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -600,17 +600,17 @@ discard block |
||
| 600 | 600 | * @return array |
| 601 | 601 | * @throws Exception\TransportException |
| 602 | 602 | */ |
| 603 | - public function insertBatchFiles($table_name, $file_names, $columns_array,$format="CSV") |
|
| 603 | + public function insertBatchFiles($table_name, $file_names, $columns_array, $format = "CSV") |
|
| 604 | 604 | { |
| 605 | 605 | if (is_string($file_names)) |
| 606 | 606 | { |
| 607 | - $file_names=[$file_names]; |
|
| 607 | + $file_names = [$file_names]; |
|
| 608 | 608 | } |
| 609 | 609 | if ($this->getCountPendingQueue() > 0) { |
| 610 | 610 | throw new QueryException('Queue must be empty, before insertBatch, need executeAsync'); |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - if (!in_array($format,$this->_support_format)) |
|
| 613 | + if (!in_array($format, $this->_support_format)) |
|
| 614 | 614 | { |
| 615 | 615 | throw new QueryException('Format not support in insertBatchFiles'); |
| 616 | 616 | } |
@@ -619,17 +619,17 @@ discard block |
||
| 619 | 619 | |
| 620 | 620 | foreach ($file_names as $fileName) { |
| 621 | 621 | if (!is_file($fileName) || !is_readable($fileName)) { |
| 622 | - throw new QueryException('Cant read file: ' . $fileName.' '.(is_file($fileName)?'':' is not file')); |
|
| 622 | + throw new QueryException('Cant read file: ' . $fileName . ' ' . (is_file($fileName) ? '' : ' is not file')); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | if (!$columns_array) |
| 626 | 626 | { |
| 627 | - $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
|
| 627 | + $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format; |
|
| 628 | 628 | |
| 629 | 629 | } |
| 630 | 630 | else |
| 631 | 631 | { |
| 632 | - $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
|
| 632 | + $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format; |
|
| 633 | 633 | |
| 634 | 634 | } |
| 635 | 635 | $result[$fileName] = $this->transport()->writeAsyncCSV($sql, $fileName); |
@@ -656,25 +656,25 @@ discard block |
||
| 656 | 656 | * @param string $format |
| 657 | 657 | * @return Transport\CurlerRequest |
| 658 | 658 | */ |
| 659 | - public function insertBatchStream($table_name, $columns_array,$format="CSV") |
|
| 659 | + public function insertBatchStream($table_name, $columns_array, $format = "CSV") |
|
| 660 | 660 | { |
| 661 | 661 | if ($this->getCountPendingQueue() > 0) { |
| 662 | 662 | throw new QueryException('Queue must be empty, before insertBatch, need executeAsync'); |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - if (!in_array($format,$this->_support_format)) |
|
| 665 | + if (!in_array($format, $this->_support_format)) |
|
| 666 | 666 | { |
| 667 | 667 | throw new QueryException('Format not support in insertBatchFiles'); |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | if (!$columns_array) |
| 671 | 671 | { |
| 672 | - $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
|
| 672 | + $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format; |
|
| 673 | 673 | |
| 674 | 674 | } |
| 675 | 675 | else |
| 676 | 676 | { |
| 677 | - $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
|
| 677 | + $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format; |
|
| 678 | 678 | |
| 679 | 679 | } |
| 680 | 680 | |
@@ -739,16 +739,16 @@ discard block |
||
| 739 | 739 | * @throws Exception\TransportException |
| 740 | 740 | * @throws \Exception |
| 741 | 741 | */ |
| 742 | - public function tablesSize($flatList=false) |
|
| 742 | + public function tablesSize($flatList = false) |
|
| 743 | 743 | { |
| 744 | - $z=$this->select(' |
|
| 744 | + $z = $this->select(' |
|
| 745 | 745 | SELECT table,database, |
| 746 | 746 | formatReadableSize(sum(bytes)) as size, |
| 747 | 747 | sum(bytes) as sizebytes, |
| 748 | 748 | min(min_date) as min_date, |
| 749 | 749 | max(max_date) as max_date |
| 750 | 750 | FROM system.parts |
| 751 | - WHERE active AND database=\''.$this->settings()->getDatabase().'\' |
|
| 751 | + WHERE active AND database=\''.$this->settings()->getDatabase() . '\' |
|
| 752 | 752 | GROUP BY table,database |
| 753 | 753 | '); |
| 754 | 754 | |
@@ -771,12 +771,12 @@ discard block |
||
| 771 | 771 | * @throws Exception\TransportException |
| 772 | 772 | * @throws \Exception |
| 773 | 773 | */ |
| 774 | - public function isExists($database,$table) |
|
| 774 | + public function isExists($database, $table) |
|
| 775 | 775 | { |
| 776 | 776 | return $this->select(' |
| 777 | 777 | SELECT * |
| 778 | 778 | FROM system.tables |
| 779 | - WHERE name=\''.$table.'\' AND database=\''.$database.'\'' |
|
| 779 | + WHERE name=\''.$table . '\' AND database=\'' . $database . '\'' |
|
| 780 | 780 | )->rowsAsTree('name'); |
| 781 | 781 | } |
| 782 | 782 | |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | return $this->select(' |
| 796 | 796 | SELECT * |
| 797 | 797 | FROM system.parts |
| 798 | - WHERE like(table,\'%' . $table . '%\') AND database=\''.$this->settings()->getDatabase().'\' |
|
| 798 | + WHERE like(table,\'%' . $table . '%\') AND database=\'' . $this->settings()->getDatabase() . '\' |
|
| 799 | 799 | ORDER BY max_date ' . ($limit > 0 ? ' LIMIT ' . intval($limit) : '') |
| 800 | 800 | )->rowsAsTree('name'); |
| 801 | 801 | } |
@@ -810,8 +810,8 @@ discard block |
||
| 810 | 810 | public function dropPartition($dataBaseTableName, $partition_id) |
| 811 | 811 | { |
| 812 | 812 | |
| 813 | - $partition_id=trim($partition_id,'\''); |
|
| 814 | - $this->settings()->set('replication_alter_partitions_sync',2); |
|
| 813 | + $partition_id = trim($partition_id, '\''); |
|
| 814 | + $this->settings()->set('replication_alter_partitions_sync', 2); |
|
| 815 | 815 | $state = $this->write('ALTER TABLE {dataBaseTableName} DROP PARTITION :partion_id', [ |
| 816 | 816 | 'dataBaseTableName' => $dataBaseTableName, |
| 817 | 817 | 'partion_id' => $partition_id |
@@ -829,12 +829,12 @@ discard block |
||
| 829 | 829 | */ |
| 830 | 830 | public function truncateTable($tableName) |
| 831 | 831 | { |
| 832 | - $partions=$this->partitions($tableName); |
|
| 833 | - $out=[]; |
|
| 832 | + $partions = $this->partitions($tableName); |
|
| 833 | + $out = []; |
|
| 834 | 834 | foreach ($partions as $part_key=>$part) |
| 835 | 835 | { |
| 836 | - $part_id=$part['partition']; |
|
| 837 | - $out[$part_id]=$this->dropPartition($tableName,$part_id); |
|
| 836 | + $part_id = $part['partition']; |
|
| 837 | + $out[$part_id] = $this->dropPartition($tableName, $part_id); |
|
| 838 | 838 | } |
| 839 | 839 | return $out; |
| 840 | 840 | } |
@@ -869,9 +869,9 @@ discard block |
||
| 869 | 869 | } |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - $result=[]; |
|
| 872 | + $result = []; |
|
| 873 | 873 | foreach ($drop as $partition_id) { |
| 874 | - $result[$partition_id]=$this->dropPartition($table_name, $partition_id); |
|
| 874 | + $result[$partition_id] = $this->dropPartition($table_name, $partition_id); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | return $result; |
@@ -109,13 +109,13 @@ discard block |
||
| 109 | 109 | CURLOPT_SSL_VERIFYHOST => 0, |
| 110 | 110 | CURLOPT_SSL_VERIFYPEER => false, |
| 111 | 111 | CURLOPT_TIMEOUT => 10, |
| 112 | - CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
| 112 | + CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
| 113 | 113 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
| 114 | 114 | CURLOPT_MAXREDIRS => 10, |
| 115 | 115 | CURLOPT_HEADER => TRUE, |
| 116 | 116 | CURLOPT_FOLLOWLOCATION => TRUE, |
| 117 | - CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
| 118 | - CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
| 117 | + CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
| 118 | + CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
| 119 | 119 | CURLOPT_RETURNTRANSFER => TRUE, |
| 120 | 120 | CURLOPT_USERAGENT => 'smi2/PHPClickHouse/client', |
| 121 | 121 | ); |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | public function setReadFunction($callback) |
| 236 | 236 | { |
| 237 | - $this->options[CURLOPT_READFUNCTION]=$callback; |
|
| 237 | + $this->options[CURLOPT_READFUNCTION] = $callback; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | |
| 353 | 353 | public function getHeaders() |
| 354 | 354 | { |
| 355 | - $head=[]; |
|
| 355 | + $head = []; |
|
| 356 | 356 | foreach ($this->headers as $key=>$value) |
| 357 | - $head[]= sprintf("%s: %s", $key, $value); |
|
| 357 | + $head[] = sprintf("%s: %s", $key, $value); |
|
| 358 | 358 | return $head; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -628,8 +628,8 @@ discard block |
||
| 628 | 628 | throw new \Exception('setFunctionProgress not is_callable'); |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $this->option(CURLOPT_NOPROGRESS,false); |
|
| 632 | - $this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0 |
|
| 631 | + $this->option(CURLOPT_NOPROGRESS, false); |
|
| 632 | + $this->option(CURLOPT_PROGRESSFUNCTION, $callback); // version 5.5.0 |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | if ($this->options[CURLOPT_VERBOSE]) { |
| 695 | - echo "\n-----------BODY REQUEST----------\n".$curl_opt[CURLOPT_POSTFIELDS]."\n------END--------\n"; |
|
| 695 | + echo "\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n"; |
|
| 696 | 696 | } |
| 697 | 697 | curl_setopt_array($this->handle, $curl_opt); |
| 698 | 698 | return true; |
@@ -353,8 +353,9 @@ discard block |
||
| 353 | 353 | public function getHeaders() |
| 354 | 354 | { |
| 355 | 355 | $head=[]; |
| 356 | - foreach ($this->headers as $key=>$value) |
|
| 357 | - $head[]= sprintf("%s: %s", $key, $value); |
|
| 356 | + foreach ($this->headers as $key=>$value) { |
|
| 357 | + $head[]= sprintf("%s: %s", $key, $value); |
|
| 358 | + } |
|
| 358 | 359 | return $head; |
| 359 | 360 | } |
| 360 | 361 | |
@@ -394,8 +395,7 @@ discard block |
||
| 394 | 395 | if ($flag) { |
| 395 | 396 | $this->_httpCompression = $flag; |
| 396 | 397 | $this->options[CURLOPT_ENCODING] = 'gzip'; |
| 397 | - } |
|
| 398 | - else |
|
| 398 | + } else |
|
| 399 | 399 | { |
| 400 | 400 | $this->_httpCompression = false; |
| 401 | 401 | unset($this->options[CURLOPT_ENCODING]); |
@@ -176,8 +176,7 @@ discard block |
||
| 176 | 176 | foreach (explode("\r\n", $header_text) as $i => $line) { |
| 177 | 177 | if ($i === 0) { |
| 178 | 178 | $headers['http_code'] = $line; |
| 179 | - } |
|
| 180 | - else { |
|
| 179 | + } else { |
|
| 181 | 180 | $r = explode(': ', $line); |
| 182 | 181 | if (sizeof($r) == 2) { |
| 183 | 182 | $headers[$r[0]] = $r[1]; |
@@ -354,8 +353,7 @@ discard block |
||
| 354 | 353 | if (sizeof($add)) { |
| 355 | 354 | if ($canAdd >= sizeof($add)) { |
| 356 | 355 | $ll = $add; |
| 357 | - } |
|
| 358 | - else { |
|
| 356 | + } else { |
|
| 359 | 357 | $ll = array_rand($add, $canAdd); |
| 360 | 358 | if (!is_array($ll)) { |
| 361 | 359 | $ll = array($ll => $ll); |