File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 15
15
namespace FOD \DBALClickHouse ;
16
16
17
17
use ClickHouseDB \Client as Smi2CHClient ;
18
+ use ClickHouseDB \Exception \TransportException ;
18
19
use Doctrine \DBAL \Driver \Connection ;
20
+ use Doctrine \DBAL \Driver \PingableConnection ;
21
+ use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
19
22
use Doctrine \DBAL \ParameterType ;
20
23
use Doctrine \DBAL \Platforms \AbstractPlatform ;
21
24
22
25
/**
23
26
* ClickHouse implementation for the Connection interface.
24
27
*/
25
- class ClickHouseConnection implements Connection
28
+ class ClickHouseConnection implements Connection, PingableConnection, ServerInfoAwareConnection
26
29
{
27
30
/** @var Smi2CHClient */
28
31
protected $ smi2CHClient ;
@@ -144,4 +147,32 @@ public function errorInfo()
144
147
{
145
148
throw new \LogicException ('You need to implement ClickHouseConnection::errorInfo() ' );
146
149
}
150
+
151
+ /**
152
+ * {@inheritDoc}
153
+ */
154
+ public function ping ()
155
+ {
156
+ return $ this ->smi2CHClient ->ping ();
157
+ }
158
+
159
+ /**
160
+ * {@inheritDoc}
161
+ */
162
+ public function getServerVersion ()
163
+ {
164
+ try {
165
+ return $ this ->smi2CHClient ->getServerVersion ();
166
+ } catch (TransportException $ exception ) {
167
+ return null ;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * {@inheritDoc}
173
+ */
174
+ public function requiresQueryForServerVersion ()
175
+ {
176
+ return true ;
177
+ }
147
178
}
Original file line number Diff line number Diff line change 12
12
namespace FOD \DBALClickHouse \Tests ;
13
13
14
14
use Doctrine \DBAL \DBALException ;
15
+ use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
15
16
use FOD \DBALClickHouse \ClickHouseException ;
16
17
use FOD \DBALClickHouse \Connection ;
17
18
use PHPUnit \Framework \TestCase ;
@@ -139,4 +140,20 @@ public function testIsRollbackOnly()
139
140
$ this ->expectException (DBALException::class);
140
141
$ this ->connection ->isRollbackOnly ();
141
142
}
143
+
144
+ public function testPing ()
145
+ {
146
+ $ this ->assertTrue ($ this ->connection ->ping ());
147
+ }
148
+
149
+ public function testGetServerVersion ()
150
+ {
151
+ $ conn = $ this ->connection ->getWrappedConnection ();
152
+ if ($ conn instanceof ServerInfoAwareConnection) {
153
+ $ this ->assertRegExp ('/(^[0-9]+.[0-9]+.[0-9]+.[0-9]$)/mi ' , $ conn ->getServerVersion ());
154
+ } else {
155
+ $ this ->fail (sprintf ('`%s` does not implement the `%s` interface ' , \get_class ($ conn ),
156
+ ServerInfoAwareConnection::class));
157
+ }
158
+ }
142
159
}
You can’t perform that action at this time.
0 commit comments