2323namespace Crate \DBAL \Driver \PDOCrate ;
2424
2525use Crate \PDO \PDOCrateDB ;
26+ use Crate \PDO \PDOStatement ;
2627use Doctrine \DBAL \Driver \PDO \Exception ;
27- use Doctrine \DBAL \Driver \PDO \Statement ;
28- use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
29- use Doctrine \DBAL \Driver \Statement as StatementInterface ;
28+ use Doctrine \DBAL \Driver \Result as ResultInterface ;
29+ use Doctrine \DBAL \Driver \Connection as ConnectionInterface ;
30+ use Doctrine \DBAL \ParameterType ;
31+ use PDO ;
32+ use PDOException ;
3033
31- class PDOConnection extends PDOCrateDB implements ServerInfoAwareConnection
34+ class PDOConnection implements ConnectionInterface
3235{
36+
37+ private PDOCrateDB $ connection ;
38+
3339 /**
3440 * @param string $dsn
3541 * @param string $user
@@ -38,19 +44,20 @@ class PDOConnection extends PDOCrateDB implements ServerInfoAwareConnection
3844 */
3945 public function __construct ($ dsn , $ user = null , $ password = null , ?array $ options = null )
4046 {
41- parent :: __construct ($ dsn , $ user , $ password , $ options );
42- $ this ->setAttribute (\ PDO ::ATTR_STATEMENT_CLASS , CrateStatement ::class);
43- $ this ->setAttribute (\ PDO ::ATTR_ERRMODE , \ PDO ::ERRMODE_EXCEPTION );
47+ $ this -> connection = new PDOCrateDB ($ dsn , $ user , $ password , $ options );
48+ $ this ->connection -> setAttribute (PDO ::ATTR_STATEMENT_CLASS , PDOStatement ::class);
49+ $ this ->connection -> setAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
4450 }
4551
46- /**
47- * Checks whether a query is required to retrieve the database server version.
48- *
49- * @return boolean True if a query is required to retrieve the database server version, false otherwise.
50- */
51- public function requiresQueryForServerVersion ()
52+ public function getServerVersion ()
5253 {
53- return false ;
54+ // Unable to detect platform version.
55+ return null ;
56+ }
57+
58+ public function getNativeConnection (): PDOCrateDB
59+ {
60+ return $ this ->connection ;
5461 }
5562
5663 /**
@@ -61,13 +68,10 @@ public function requiresQueryForServerVersion()
6168 * - https://github.com/doctrine/dbal/pull/517
6269 * - https://github.com/doctrine/dbal/pull/373
6370 */
64- public function prepare ($ sql , $ options = null ): StatementInterface
71+ public function prepare ($ sql , $ options = [] ): CrateStatement
6572 {
6673 try {
67- $ stmt = $ this ->connection ->prepare ($ sql , $ options );
68- assert ($ stmt instanceof PDOStatement);
69-
70- return new Statement ($ stmt );
74+ return new CrateStatement ($ this ->connection , $ sql , $ options );
7175 } catch (PDOException $ exception ) {
7276 throw Exception::new ($ exception );
7377 }
@@ -80,12 +84,60 @@ public function exec($sql): int
8084 {
8185 try {
8286 $ result = $ this ->connection ->exec ($ sql );
87+ assert ($ result !== false );
88+ return $ result ;
89+ } catch (PDOException $ exception ) {
90+ throw Exception::new ($ exception );
91+ }
92+ }
8393
94+ /**
95+ * {@inheritDoc}
96+ */
97+ public function quer2y (string $ sql ): Result
98+ {
99+ try {
100+ $ result = $ this ->connection ->query ($ sql );
84101 assert ($ result !== false );
102+ return new Result ($ result );
103+ } catch (PDOException $ exception ) {
104+ throw Exception::new ($ exception );
105+ }
106+ }
85107
86- return $ result ;
108+ public function query (string $ sql ): ResultInterface
109+ {
110+ try {
111+ $ stmt = $ this ->prepare ($ sql );
112+ $ stmt ->execute ();
113+ return new Result ($ stmt );
87114 } catch (PDOException $ exception ) {
88115 throw Exception::new ($ exception );
89116 }
90117 }
118+
119+ public function quote ($ value , $ type = ParameterType::STRING ): string
120+ {
121+ return $ this ->connection ->quote ($ value , $ type );
122+ }
123+
124+ public function lastInsertId ($ name = null ): string
125+ {
126+ return $ this ->connection ->lastInsertId ($ name );
127+ }
128+
129+ public function beginTransaction (): bool
130+ {
131+ return true ;
132+ }
133+
134+ public function commit (): bool
135+ {
136+ return true ;
137+ }
138+
139+ public function rollBack (): bool
140+ {
141+ return true ;
142+ }
91143}
0 commit comments