|
44 | 44 | */ |
45 | 45 | class ClickHouseAPI |
46 | 46 | { |
| 47 | + /* |
| 48 | + * Trait for async requests |
| 49 | + */ |
47 | 50 | use ClickHouseSlots; |
| 51 | + /* |
| 52 | + * Trait for currentDatabase() and setCurrentDatabase(); |
| 53 | + */ |
| 54 | + use ClickHouseSessions; |
| 55 | + |
48 | 56 | /** |
49 | 57 | * Protocol for access to ClickHouse server |
50 | 58 | * |
@@ -185,13 +193,6 @@ class ClickHouseAPI |
185 | 193 | */ |
186 | 194 | public $hook_before_api_call = false; |
187 | 195 |
|
188 | | - /** |
189 | | - * Auto-create session_id and send it with each request |
190 | | - * |
191 | | - * @var boolean |
192 | | - */ |
193 | | - public $session_autocreate = false; |
194 | | - |
195 | 196 | /** |
196 | 197 | * True if running under windows, false otherwise |
197 | 198 | * |
@@ -423,7 +424,7 @@ public function doQuery( |
423 | 424 | $password = $this->pass; |
424 | 425 |
|
425 | 426 | // Set session if need |
426 | | - if (!empty($session_id) && $this->getSession() != $session_id) { |
| 427 | + if (!empty($session_id) && ($this->getSession() !== $session_id)) { |
427 | 428 | $old_session = $this->setSession($session_id); |
428 | 429 | } else { |
429 | 430 | if ($this->session_autocreate && $this->getSession() === null) { |
@@ -616,32 +617,6 @@ public function getOption($key) |
616 | 617 | return isset($this->options[$key]) ? $this->options[$key] : null; |
617 | 618 | } |
618 | 619 |
|
619 | | - /** |
620 | | - * Set session_id to http-request options |
621 | | - * if session_id not specified (or specified as null) create and set random. |
622 | | - * |
623 | | - * @param string|null $session_id session_id or null for generate new id |
624 | | - * @param boolean $overwrite false = set only if session not defined, true = always |
625 | | - * @return string|null Return old value of session_id option |
626 | | - */ |
627 | | - public function setSession($session_id = null, $overwrite = true) |
628 | | - { |
629 | | - if (\is_null($session_id)) { |
630 | | - $session_id = \md5(\uniqid(\mt_rand(0, \PHP_INT_MAX), true)); |
631 | | - } |
632 | | - return $this->setOption('session_id', $session_id, $overwrite); |
633 | | - } |
634 | | - |
635 | | - /** |
636 | | - * Return current session_id from http-options. Return null if not exists. |
637 | | - * |
638 | | - * @return string|null |
639 | | - */ |
640 | | - public function getSession() |
641 | | - { |
642 | | - return $this->getOption('session_id'); |
643 | | - } |
644 | | - |
645 | 620 | /** |
646 | 621 | * Delete http-option by specified key |
647 | 622 | * |
@@ -733,7 +708,7 @@ public function versionSendQuery() |
733 | 708 | { |
734 | 709 | // save to_slot and old session_id for restore it after complete |
735 | 710 | $old_to_slot = $this->to_slot; |
736 | | - $old_sess = $this->setSession(null, false); |
| 711 | + $old_sess = $this->setSession(false, false); |
737 | 712 |
|
738 | 713 | $query = 'SELECT version()'; |
739 | 714 |
|
|
0 commit comments