diff --git a/src/Client/Http/RequestFactory.php b/src/Client/Http/RequestFactory.php index 397432f..10b3138 100644 --- a/src/Client/Http/RequestFactory.php +++ b/src/Client/Http/RequestFactory.php @@ -33,7 +33,7 @@ public function prepareRequest(RequestOptions $requestOptions) : RequestInterfac PHP_QUERY_RFC3986 ); - return $this->requestFactory->createRequest('POST', $query) + return $this->requestFactory->createRequest('POST', $query === '' ? '' : '?' . $query) ->withBody($this->streamFactory->createStream($requestOptions->sql)); } } diff --git a/tests/Client/SelectTest.php b/tests/Client/SelectTest.php index bd26d94..ef2661f 100644 --- a/tests/Client/SelectTest.php +++ b/tests/Client/SelectTest.php @@ -4,6 +4,7 @@ namespace SimPod\ClickHouseClient\Tests\Client; +use SimPod\ClickHouseClient\Exception\ServerError; use SimPod\ClickHouseClient\Format\Json; use SimPod\ClickHouseClient\Format\JsonCompact; use SimPod\ClickHouseClient\Format\JsonEachRow; @@ -130,4 +131,12 @@ public function providerJsonEachRow() : iterable CLICKHOUSE, ]; } + + public function testSettingsArePassed() : void + { + self::expectException(ServerError::class); + $this->expectExceptionMessage("DB::Exception: Database `non-existent` doesn't exist"); + + $this->client->select('SELECT 1', new JsonCompact(), ['database' => 'non-existent']); + } }