|
21 | 21 | */ |
22 | 22 | class Connection |
23 | 23 | { |
| 24 | + private const Drivers = [ |
| 25 | + 'firebird' => Drivers\Ibase\Connection::class, |
| 26 | + 'mysqli' => Drivers\MySQLi\Connection::class, |
| 27 | + 'odbc' => Drivers\ODBC\Connection::class, |
| 28 | + 'oracle' => Drivers\OCI8\Connection::class, |
| 29 | + 'pdo' => Drivers\PDO\Connection::class, |
| 30 | + 'postgre' => Drivers\PgSQL\Connection::class, |
| 31 | + 'sqlite3' => Drivers\SQLite3\Connection::class, |
| 32 | + 'sqlite' => Drivers\SQLite3\Connection::class, |
| 33 | + 'sqlsrv' => Drivers\SQLSrv\Connection::class, |
| 34 | + ]; |
| 35 | + |
24 | 36 | /** function (Event $event); Occurs after query is executed */ |
25 | 37 | public ?array $onEvent = []; |
26 | 38 | private array $config; |
@@ -129,8 +141,7 @@ final public function connect(): void |
129 | 141 | $class = $this->config['driver']; |
130 | 142 |
|
131 | 143 | } else { |
132 | | - $class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($this->config['driver']))); |
133 | | - $class = "Dibi\\Drivers\\{$class}Driver"; |
| 144 | + $class = self::Drivers[strtolower($this->config['driver'])] ?? throw new Exception("Unknown driver '{$this->config['driver']}'."); |
134 | 145 | if (!class_exists($class)) { |
135 | 146 | throw new Exception("Unable to create instance of Dibi driver '$class'."); |
136 | 147 | } |
@@ -284,7 +295,7 @@ final public function nativeQuery(#[Language('SQL')] string $sql): Result |
284 | 295 | throw $e; |
285 | 296 | } |
286 | 297 |
|
287 | | - $res = $this->createResultSet($res ?: new Drivers\NoDataResult(max(0, $this->driver->getAffectedRows()))); |
| 298 | + $res = $this->createResultSet($res ?: new Drivers\Dummy\Result(max(0, $this->driver->getAffectedRows()))); |
288 | 299 | if ($event) { |
289 | 300 | $this->onEvent($event->done($res)); |
290 | 301 | } |
|
0 commit comments