@@ -527,7 +527,10 @@ public function isSupported($fe_key = 'session_id', $re_check = false)
527527    /** 
528528     * Return version of ClickHouse server by function SELECT version() 
529529     * 
530-      * The response is cached 
530+      * Do SELECT version() + session_id to see if a session is supported or not 
531+      * if session_id not supported, request is send again, but without session_id. 
532+      * - Depending on result, the isSupported('session_id') is set true or false. 
533+      * - If server version response unrecognized, isSupported('query') set false. 
531534     * 
532535     * @param boolean $re_check Set true for re-send query to server 
533536     * @return string|boolean String version or false if error 
@@ -536,32 +539,40 @@ public function getVersion($re_check = false)
536539    {
537540        if  (\is_null ($ this server_version ) || $ re_check
538541            $ old_sess$ this setSession (null , false );
539-             $ session_id$ this getSession ();
540542            $ query'SELECT version() ' ;
541-             $ user$ this user ;
542-             $ password$ this pass ;
543-             $ h_opt_arr\compact ('query ' , 'user ' , 'password ' , 'session_id ' );
544-             $ ans$ this doApiCall ($ this server_url , $ h_opt_arr
545-             if  ($ ans'code ' ] == 200 ) {
546-                 $ this support_fe ['session_id ' ] = true ;
547-             } else  {
548-                 $ this support_fe ['session_id ' ] = false ;
549-                 $ this session_autocreate  = false ;
550-                 unset($ h_opt_arr'session_id ' ]);
551-                 // if session_id unsupported send request again 
552-                 if  ($ ans'code ' ] == 404 ) {
553-                     $ ans$ this doApiCall ($ this server_url , $ h_opt_arr
554-                 }
543+             $ ans$ this doGet ($ query'session_id '  => $ this getSession ()]);
544+             if  (!($ this support_fe ['session_id ' ] = $ ans'code ' ] != 404 )) {
545+                 $ ans$ this doGet ($ query
555546            }
556547            $ verexplode ("\n" , $ ans'response ' ]);
557548            $ vercount ($ ver2  && strlen ($ ver0 ]) < 32 ) ? $ ver0 ] : "Unknown " ;
558549            $ this support_fe ['query ' ] = \is_string ($ ver\count (\explode (". " , $ ver2 );
559550            if  (!$ this support_fe ['query ' ]) {
560551                $ this support_fe ['session_id ' ] = false ;
561552            }
553+             if  (!$ this support_fe ['session_id ' ]) {
554+                 $ this session_autocreate  = false ;
555+             }
562556            $ this server_version  = $ ver
563557            $ this setOption ('session_id ' , $ old_sess
564558        }
565559        return  $ this server_version ;
566560    }
561+ 
562+     /** 
563+      * Do GET-request with base options (query, user, password) + specified options 
564+      * 
565+      * The result array is the same as for the function doApiCall 
566+      * 
567+      * @param string $query will be set as an option ?query=... 
568+      * @param array $h_opt Other in-url-options for make GET-request 
569+      * @return array 
570+      */ 
571+     public  function  doGet ($ query$ h_opt
572+     {
573+         $ user$ this user ;
574+         $ password$ this pass ;
575+         $ h_opt_arr\array_merge (\compact ('query ' , 'user ' , 'password ' ), $ h_opt
576+         return  $ this doApiCall ($ this server_url , $ h_opt_arr
577+     }
567578}
0 commit comments