diff --git a/src/Database/Connection.php b/src/Database/Connection.php index 3788127e9..fc7db53bc 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -26,7 +26,7 @@ class Connection /** @var array Occurs after query is executed */ public array $onQuery = []; - private Driver $driver; + private Drivers\Engine $engine; private SqlPreprocessor $preprocessor; private ?PDO $pdo = null; @@ -68,9 +68,9 @@ public function connect(): void $class = empty($this->options['driverClass']) ? 'Nette\Database\Drivers\\' . ucfirst(str_replace('sql', 'Sql', $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME))) . 'Driver' : $this->options['driverClass']; - $this->driver = new $class; + $this->engine = new $class; $this->preprocessor = new SqlPreprocessor($this); - $this->driver->initialize($this, $this->options); + $this->engine->initialize($this, $this->options); Arrays::invoke($this->onConnect, $this); } @@ -101,25 +101,25 @@ public function getPdo(): PDO } - public function getDriver(): Driver + /** @deprecated use getDriver() */ + public function getSupplementalDriver(): Drivers\Engine { + trigger_error(__METHOD__ . '() is deprecated, use getDriver()', E_USER_DEPRECATED); $this->connect(); - return $this->driver; + return $this->engine; } - /** @deprecated use getDriver() */ - public function getSupplementalDriver(): Driver + public function getDatabaseEngine(): Drivers\Engine { - trigger_error(__METHOD__ . '() is deprecated, use getDriver()', E_USER_DEPRECATED); $this->connect(); - return $this->driver; + return $this->engine; } public function getReflection(): Reflection { - return new Reflection($this->getDriver()); + return new Reflection($this->getDatabaseEngine()); } @@ -136,7 +136,7 @@ public function getInsertId(?string $sequence = null): string $res = $this->getPdo()->lastInsertId($sequence); return $res === false ? '0' : $res; } catch (PDOException $e) { - throw $this->driver->convertException($e); + throw $this->engine->convertException($e); } } diff --git a/src/Database/Driver.php b/src/Database/Drivers/Engine.php similarity index 88% rename from src/Database/Driver.php rename to src/Database/Drivers/Engine.php index 40c09a076..07a38479a 100644 --- a/src/Database/Driver.php +++ b/src/Database/Drivers/Engine.php @@ -7,13 +7,15 @@ declare(strict_types=1); -namespace Nette\Database; +namespace Nette\Database\Drivers; + +use Nette\Database; /** - * Supplemental PDO database driver. + * Engine-specific behaviors, features and SQL dialects. */ -interface Driver +interface Engine { public const SupportSequence = 'sequence', @@ -26,12 +28,12 @@ interface Driver /** * Initializes connection. */ - function initialize(Connection $connection, array $options): void; + function initialize(Database\Connection $connection, array $options): void; /** * Converts PDOException to DriverException or its descendant. */ - function convertException(\PDOException $e): DriverException; + function convertException(\PDOException $e): Database\DriverException; /** * Delimites identifier for use in a SQL statement. diff --git a/src/Database/Drivers/MsSqlDriver.php b/src/Database/Drivers/MsSqlDriver.php index cb078b94c..851f243fe 100644 --- a/src/Database/Drivers/MsSqlDriver.php +++ b/src/Database/Drivers/MsSqlDriver.php @@ -15,7 +15,7 @@ /** * Supplemental MS SQL database driver. */ -class MsSqlDriver implements Nette\Database\Driver +class MsSqlDriver implements Engine { private Nette\Database\Connection $connection; diff --git a/src/Database/Drivers/MySqlDriver.php b/src/Database/Drivers/MySqlDriver.php index 4c5a8acd0..9f95588a0 100644 --- a/src/Database/Drivers/MySqlDriver.php +++ b/src/Database/Drivers/MySqlDriver.php @@ -15,7 +15,7 @@ /** * Supplemental MySQL database driver. */ -class MySqlDriver implements Nette\Database\Driver +class MySqlDriver implements Engine { private Nette\Database\Connection $connection; private bool $convertBoolean; diff --git a/src/Database/Drivers/OciDriver.php b/src/Database/Drivers/OciDriver.php index 6f5fc7e57..3e83a8547 100644 --- a/src/Database/Drivers/OciDriver.php +++ b/src/Database/Drivers/OciDriver.php @@ -15,7 +15,7 @@ /** * Supplemental Oracle database driver. */ -class OciDriver implements Nette\Database\Driver +class OciDriver implements Engine { private Nette\Database\Connection $connection; private string $fmtDateTime; diff --git a/src/Database/Drivers/OdbcDriver.php b/src/Database/Drivers/OdbcDriver.php index 078a202cc..f89bf6e42 100644 --- a/src/Database/Drivers/OdbcDriver.php +++ b/src/Database/Drivers/OdbcDriver.php @@ -15,7 +15,7 @@ /** * Supplemental ODBC database driver. */ -class OdbcDriver implements Nette\Database\Driver +class OdbcDriver implements Engine { public function initialize(Nette\Database\Connection $connection, array $options): void { diff --git a/src/Database/Drivers/PgSqlDriver.php b/src/Database/Drivers/PgSqlDriver.php index 5ed962ee8..7ab078959 100644 --- a/src/Database/Drivers/PgSqlDriver.php +++ b/src/Database/Drivers/PgSqlDriver.php @@ -15,7 +15,7 @@ /** * Supplemental PostgreSQL database driver. */ -class PgSqlDriver implements Nette\Database\Driver +class PgSqlDriver implements Engine { private Nette\Database\Connection $connection; diff --git a/src/Database/Drivers/SqliteDriver.php b/src/Database/Drivers/SqliteDriver.php index 7baf584c1..0afdf3097 100644 --- a/src/Database/Drivers/SqliteDriver.php +++ b/src/Database/Drivers/SqliteDriver.php @@ -15,7 +15,7 @@ /** * Supplemental SQLite3 database driver. */ -class SqliteDriver implements Nette\Database\Driver +class SqliteDriver implements Engine { private Nette\Database\Connection $connection; private string $fmtDateTime; diff --git a/src/Database/Drivers/SqlsrvDriver.php b/src/Database/Drivers/SqlsrvDriver.php index 0cabf0798..a9d6415a5 100644 --- a/src/Database/Drivers/SqlsrvDriver.php +++ b/src/Database/Drivers/SqlsrvDriver.php @@ -15,7 +15,7 @@ /** * Supplemental SQL Server 2005 and later database driver. */ -class SqlsrvDriver implements Nette\Database\Driver +class SqlsrvDriver implements Engine { private Nette\Database\Connection $connection; diff --git a/src/Database/Reflection.php b/src/Database/Reflection.php index bc288b091..d85be54ad 100644 --- a/src/Database/Reflection.php +++ b/src/Database/Reflection.php @@ -19,7 +19,7 @@ final class Reflection public function __construct( - private readonly Driver $driver, + private readonly Drivers\Engine $engine, ) { unset($this->tables); } @@ -67,16 +67,16 @@ private function getFullName(string $name): string /** @internal */ - public function getDriver(): Driver + public function getDatabaseEngine(): Drivers\Engine { - return $this->driver; + return $this->engine; } private function initTables(): void { $res = []; - foreach ($this->driver->getTables() as $row) { + foreach ($this->engine->getTables() as $row) { $res[$row['fullName'] ?? $row['name']] = new Table($this, $row['name'], $row['view'], $row['fullName'] ?? null); } $this->tables = $res; diff --git a/src/Database/Reflection/Table.php b/src/Database/Reflection/Table.php index a051de557..da684cc7b 100644 --- a/src/Database/Reflection/Table.php +++ b/src/Database/Reflection/Table.php @@ -48,7 +48,7 @@ public function getColumn(string $name): Column private function initColumns(): void { $res = []; - foreach ($this->reflection->getDriver()->getColumns($this->name) as $row) { + foreach ($this->reflection->getDatabaseEngine()->getColumns($this->name) as $row) { $row['table'] = $this; $res[$row['name']] = new Column(...$row); } @@ -65,7 +65,7 @@ private function initIndexes(): void $row['primary'], is_string($row['name']) ? $row['name'] : null, ), - $this->reflection->getDriver()->getIndexes($this->name), + $this->reflection->getDatabaseEngine()->getIndexes($this->name), ); } @@ -83,7 +83,7 @@ private function initPrimaryKey(): void private function initForeignKeys(): void { $tmp = []; - foreach ($this->reflection->getDriver()->getForeignKeys($this->name) as $row) { + foreach ($this->reflection->getDatabaseEngine()->getForeignKeys($this->name) as $row) { $id = $row['name']; $foreignTable = $this->reflection->getTable($row['table']); $tmp[$id][0] = $foreignTable; diff --git a/src/Database/ResultSet.php b/src/Database/ResultSet.php index 018c74d30..580c96be1 100644 --- a/src/Database/ResultSet.php +++ b/src/Database/ResultSet.php @@ -55,7 +55,7 @@ public function __construct( $this->pdoStatement->execute(); } } catch (\PDOException $e) { - $e = $connection->getDriver()->convertException($e); + $e = $connection->getDatabaseEngine()->convertException($e); $e->queryString = $queryString; $e->params = $params; throw $e; @@ -108,7 +108,7 @@ public function getRowCount(): ?int public function getColumnTypes(): array { - $this->types ??= $this->connection->getDriver()->getColumnTypes($this->pdoStatement); + $this->types ??= $this->connection->getDatabaseEngine()->getColumnTypes($this->pdoStatement); return $this->types; } diff --git a/src/Database/SqlPreprocessor.php b/src/Database/SqlPreprocessor.php index 876ef3ca3..6f002182f 100644 --- a/src/Database/SqlPreprocessor.php +++ b/src/Database/SqlPreprocessor.php @@ -49,7 +49,7 @@ class SqlPreprocessor ]; private readonly Connection $connection; - private readonly Driver $driver; + private readonly Drivers\Engine $engine; private array $params; private array $remaining; private int $counter; @@ -62,7 +62,7 @@ class SqlPreprocessor public function __construct(Connection $connection) { $this->connection = $connection; - $this->driver = $connection->getDriver(); + $this->engine = $connection->getDatabaseEngine(); } @@ -177,10 +177,10 @@ private function formatValue(mixed $value, ?string $mode = null): string return $res; } elseif ($value instanceof \DateTimeInterface) { - return $this->driver->formatDateTime($value); + return $this->engine->formatDateTime($value); } elseif ($value instanceof \DateInterval) { - return $this->driver->formatDateInterval($value); + return $this->engine->formatDateInterval($value); } elseif ($value instanceof \BackedEnum && is_scalar($value->value)) { $this->remaining[] = $value->value; @@ -231,7 +231,7 @@ private function formatValue(mixed $value, ?string $mode = null): string $vx[] = implode(', ', $vx2); } - $select = $this->driver->isSupported(Driver::SupportMultiInsertAsSelect); + $select = $this->engine->isSupported(Drivers\Engine::SupportMultiInsertAsSelect); return '(' . implode(', ', $kx) . ($select ? ') SELECT ' : ') VALUES (') . implode($select ? ' UNION ALL SELECT ' : '), (', $vx) . ($select ? '' : ')'); } @@ -320,6 +320,6 @@ private function formatValue(mixed $value, ?string $mode = null): string private function delimite(string $name): string { - return implode('.', array_map($this->driver->delimite(...), explode('.', $name))); + return implode('.', array_map($this->engine->delimite(...), explode('.', $name))); } } diff --git a/src/Database/Structure.php b/src/Database/Structure.php index 580c2b820..2b3ae3076 100644 --- a/src/Database/Structure.php +++ b/src/Database/Structure.php @@ -94,7 +94,7 @@ public function getPrimaryKeySequence(string $table): ?string $this->needStructure(); $table = $this->resolveFQTableName($table); - if (!$this->connection->getDriver()->isSupported(Driver::SupportSequence)) { + if (!$this->connection->getDatabaseEngine()->isSupported(Drivers\Engine::SupportSequence)) { return null; } @@ -177,10 +177,10 @@ protected function needStructure(): void protected function loadStructure(): array { - $driver = $this->connection->getDriver(); + $engine = $this->connection->getDatabaseEngine(); $structure = []; - $structure['tables'] = $driver->getTables(); + $structure['tables'] = $engine->getTables(); foreach ($structure['tables'] as $tablePair) { if (isset($tablePair['fullName'])) { @@ -190,7 +190,7 @@ protected function loadStructure(): array $table = $tablePair['name']; } - $structure['columns'][strtolower($table)] = $columns = $driver->getColumns($table); + $structure['columns'][strtolower($table)] = $columns = $engine->getColumns($table); if (!$tablePair['view']) { $structure['primary'][strtolower($table)] = $this->analyzePrimaryKey($columns); @@ -233,7 +233,7 @@ protected function analyzeForeignKeys(array &$structure, string $table): void { $lowerTable = strtolower($table); - $foreignKeys = $this->connection->getDriver()->getForeignKeys($table); + $foreignKeys = $this->connection->getDatabaseEngine()->getForeignKeys($table); $fksColumnsCounts = []; foreach ($foreignKeys as $foreignKey) { diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 1e8f8bb12..79c9835fa 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -790,7 +790,7 @@ public function insert(iterable $data): ActiveRow|array|int|bool // First check sequence if (!empty($primarySequenceName) && $primaryAutoincrementKey) { - $primaryKey[$primaryAutoincrementKey] = $this->explorer->getInsertId($this->explorer->getConnection()->getDriver()->delimite($primarySequenceName)); + $primaryKey[$primaryAutoincrementKey] = $this->explorer->getInsertId($this->explorer->getConnection()->getDatabaseEngine()->delimite($primarySequenceName)); // Autoincrement primary without sequence } elseif ($primaryAutoincrementKey) { diff --git a/src/Database/Table/SqlBuilder.php b/src/Database/Table/SqlBuilder.php index 4db2d3f09..0aa8f9210 100644 --- a/src/Database/Table/SqlBuilder.php +++ b/src/Database/Table/SqlBuilder.php @@ -11,7 +11,7 @@ use Nette; use Nette\Database\Conventions; -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Nette\Database\Explorer; use Nette\Database\IStructure; use Nette\Database\SqlLiteral; @@ -46,7 +46,7 @@ class SqlBuilder protected array $reservedTableNames = []; protected array $aliases = []; protected string $currentAlias = ''; - private readonly Driver $driver; + private readonly Engine $engine; private readonly IStructure $structure; private array $cacheTableList = []; private array $expandingJoins = []; @@ -55,11 +55,11 @@ class SqlBuilder public function __construct(string $tableName, Explorer $explorer) { $this->tableName = $tableName; - $this->driver = $explorer->getConnection()->getDriver(); + $this->engine = $explorer->getConnection()->getDatabaseEngine(); $this->conventions = $explorer->getConventions(); $this->structure = $explorer->getStructure(); $tableNameParts = explode('.', $tableName); - $this->delimitedTable = implode('.', array_map($this->driver->delimite(...), $tableNameParts)); + $this->delimitedTable = implode('.', array_map($this->engine->delimite(...), $tableNameParts)); $this->checkUniqueTableName(end($tableNameParts), $tableName); } @@ -85,7 +85,7 @@ public function buildUpdateQuery(): string } if ($this->limit !== null || $this->offset) { - $this->driver->applyLimit($query, $this->limit, $this->offset); + $this->engine->applyLimit($query, $this->limit, $this->offset); } return $query; @@ -96,7 +96,7 @@ public function buildDeleteQuery(): string { $query = "DELETE FROM {$this->delimitedTable}" . $this->tryDelimite($this->buildConditions()); if ($this->limit !== null || $this->offset) { - $this->driver->applyLimit($query, $this->limit, $this->offset); + $this->engine->applyLimit($query, $this->limit, $this->offset); } return $query; @@ -119,7 +119,7 @@ public function getSelectQueryHash(?array $columns = null): string $parts[] = $this->select; } elseif ($columns) { $parts[] = [$this->delimitedTable, $columns]; - } elseif ($this->group && !$this->driver->isSupported(Driver::SupportSelectUngroupedColumns)) { + } elseif ($this->group && !$this->engine->isSupported(Engine::SupportSelectUngroupedColumns)) { $parts[] = [$this->group]; } else { $parts[] = "{$this->delimitedTable}.*"; @@ -171,7 +171,7 @@ public function buildSelectQuery(?array $columns = null): string $querySelect = $this->buildSelect($cols); - } elseif ($this->group && !$this->driver->isSupported(Driver::SupportSelectUngroupedColumns)) { + } elseif ($this->group && !$this->engine->isSupported(Engine::SupportSelectUngroupedColumns)) { $querySelect = $this->buildSelect([$this->group]); $this->parseJoins($joins, $querySelect); @@ -183,7 +183,7 @@ public function buildSelectQuery(?array $columns = null): string $queryJoins = $this->buildQueryJoins($joins, $finalJoinConditions); $query = "{$querySelect} FROM {$this->delimitedTable}{$queryJoins}{$queryCondition}{$queryEnd}"; - $this->driver->applyLimit($query, $this->limit, $this->offset); + $this->engine->applyLimit($query, $this->limit, $this->offset); return $this->tryDelimite($query); } @@ -343,7 +343,7 @@ protected function addCondition( } } - if ($this->driver->isSupported(Driver::SupportSubselect)) { + if ($this->engine->isSupported(Engine::SupportSubselect)) { $arg = null; $subSelectPlaceholderCount = substr_count($clone->getSql(), '?'); $replace = $match[2][0] . '(' . $clone->getSql() . (!$subSelectPlaceholderCount && count($clone->getSqlBuilder()->getParameters()) === 1 ? ' ?' : '') . ')'; @@ -634,7 +634,7 @@ public function parseJoinsCb(array &$joins, array $match): string $parentAlias = preg_replace('#^(.*\.)?(.*)$#', '$2', $this->tableName); // join schema keyMatch and table keyMatch to schema.table keyMatch - if ($this->driver->isSupported(Driver::SupportSchema) && count($keyMatches) > 1) { + if ($this->engine->isSupported(Engine::SupportSchema) && count($keyMatches) > 1) { $tables = $this->getCachedTableList(); if ( !isset($tables[$keyMatches[0]['key']]) @@ -795,7 +795,7 @@ protected function tryDelimite(string $s): string '#(?<=[^\w`"\[?:]|^)[a-z_][a-z0-9_]*(?=[^\w`"(\]]|$)#Di', fn(array $m): string => strtoupper($m[0]) === $m[0] ? $m[0] - : $this->driver->delimite($m[0]), + : $this->engine->delimite($m[0]), $s, ); } @@ -808,7 +808,7 @@ protected function addConditionComposition( array &$conditionsParameters, ): bool { - if ($this->driver->isSupported(Driver::SupportMultiColumnAsOrCond)) { + if ($this->engine->isSupported(Engine::SupportMultiColumnAsOrCond)) { $conditionFragment = '(' . implode(' = ? AND ', $columns) . ' = ?) OR '; $condition = substr(str_repeat($conditionFragment, count($parameters)), 0, -4); return $this->addCondition($condition, [Nette\Utils\Arrays::flatten($parameters)], $conditions, $conditionsParameters); diff --git a/tests/Database/Connection.lazy.phpt b/tests/Database/Connection.lazy.phpt index 1561dc39f..2c877d389 100644 --- a/tests/Database/Connection.lazy.phpt +++ b/tests/Database/Connection.lazy.phpt @@ -60,19 +60,19 @@ test('connect & disconnect', function () { // first connection $pdo = $connection->getPdo(); - $driver = $connection->getDriver(); + $driver = $connection->getDatabaseEngine(); Assert::same(1, $connections); // still first connection $connection->connect(); Assert::same($pdo, $connection->getPdo()); - Assert::same($driver, $connection->getDriver()); + Assert::same($driver, $connection->getDatabaseEngine()); Assert::same(1, $connections); // second connection $connection->reconnect(); $pdo2 = $connection->getPdo(); - $driver2 = $connection->getDriver(); + $driver2 = $connection->getDatabaseEngine(); Assert::notSame($pdo, $pdo2); Assert::notSame($driver, $driver2); @@ -81,6 +81,6 @@ test('connect & disconnect', function () { // third connection $connection->disconnect(); Assert::notSame($pdo2, $connection->getPdo()); - Assert::notSame($driver2, $connection->getDriver()); + Assert::notSame($driver2, $connection->getDatabaseEngine()); Assert::same(3, $connections); }); diff --git a/tests/Database/Connection.sqlite.phpt b/tests/Database/Connection.sqlite.phpt index 5bced5c7c..a19a022b0 100644 --- a/tests/Database/Connection.sqlite.phpt +++ b/tests/Database/Connection.sqlite.phpt @@ -14,12 +14,12 @@ require __DIR__ . '/../bootstrap.php'; test('formatDateTime', function () { $connection = connectToDB(['formatDateTime' => 'U'])->getConnection(); - $driver = $connection->getDriver(); - Assert::equal('254358000', $driver->formatDateTime(new DateTime('1978-01-23 00:00:00'))); + $engine = $connection->getDatabaseEngine(); + Assert::equal('254358000', $engine->formatDateTime(new DateTime('1978-01-23 00:00:00'))); }); test('formatDateTime', function () { $connection = connectToDB(['formatDateTime' => 'Y-m-d'])->getConnection(); - $driver = $connection->getDriver(); - Assert::equal('1978-01-23', $driver->formatDateTime(new DateTime('1978-01-23 00:00:00'))); + $engine = $connection->getDatabaseEngine(); + Assert::equal('1978-01-23', $engine->formatDateTime(new DateTime('1978-01-23 00:00:00'))); }); diff --git a/tests/Database/Drivers/MsSqlDriver.applyLimit.phpt b/tests/Database/Drivers/MsSqlDriver.applyLimit.phpt index 636142214..d99ec58f3 100644 --- a/tests/Database/Drivers/MsSqlDriver.applyLimit.phpt +++ b/tests/Database/Drivers/MsSqlDriver.applyLimit.phpt @@ -1,60 +1,62 @@ getDatabaseEngine(); -$driver = new Nette\Database\Drivers\MsSqlDriver; - -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, 10, 20); + $engine->applyLimit($query, 10, 20); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, 0, 20); + $engine->applyLimit($query, 0, 20); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT TOP 10 1 FROM t', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, 20); + $engine->applyLimit($query, null, 20); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT TOP 10 1 FROM t', $query); $query = ' select distinct 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same(' select distinct TOP 10 1 FROM t', $query); $query = 'UPDATE t SET'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('UPDATE TOP 10 t SET', $query); $query = 'DELETE FROM t SET'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('DELETE TOP 10 FROM t SET', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SET FROM t'; - $driver->applyLimit($query, 10, null); + $engine->applyLimit($query, 10, null); }, Nette\InvalidArgumentException::class, 'SQL query must begin with SELECT, UPDATE or DELETE command.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); diff --git a/tests/Database/Drivers/MySqlDriver.applyLimit.phpt b/tests/Database/Drivers/MySqlDriver.applyLimit.phpt index 8434fe2f5..8bb5a7a3c 100644 --- a/tests/Database/Drivers/MySqlDriver.applyLimit.phpt +++ b/tests/Database/Drivers/MySqlDriver.applyLimit.phpt @@ -11,34 +11,34 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $connection = connectToDB()->getConnection(); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 20); +$engine->applyLimit($query, 10, 20); Assert::same('SELECT 1 FROM t LIMIT 10 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 0, 20); +$engine->applyLimit($query, 0, 20); Assert::same('SELECT 1 FROM t LIMIT 0 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT 1 FROM t LIMIT 10', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, null, 20); +$engine->applyLimit($query, null, 20); Assert::same('SELECT 1 FROM t LIMIT 18446744073709551615 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT 1 FROM t LIMIT 10', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); diff --git a/tests/Database/Drivers/MySqlDriver.formatLike.phpt b/tests/Database/Drivers/MySqlDriver.formatLike.phpt index 45d7fa032..c0593f62f 100644 --- a/tests/Database/Drivers/MySqlDriver.formatLike.phpt +++ b/tests/Database/Drivers/MySqlDriver.formatLike.phpt @@ -11,22 +11,22 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $connection = connectToDB()->getConnection(); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A%B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA%BB' LIKE", $connection::literal($driver->formatLike('A%B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A%B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA%BB' LIKE", $connection::literal($engine->formatLike('A%B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike("A'B", 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA''BB' LIKE", $connection::literal($driver->formatLike("A'B", 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike("A'B", 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA''BB' LIKE", $connection::literal($engine->formatLike("A'B", 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A"B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($engine->formatLike('A"B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA\\\\BB' LIKE", $connection::literal($driver->formatLike('A\B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA\\\\BB' LIKE", $connection::literal($engine->formatLike('A\B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA\\\\%BB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\%B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA\\\\%BB' LIKE", $connection::literal($engine->formatLike('A\%B', 0)))->fetchField()); diff --git a/tests/Database/Drivers/OciDriver.applyLimit.phpt b/tests/Database/Drivers/OciDriver.applyLimit.phpt index c446108f5..a7af1ce0d 100644 --- a/tests/Database/Drivers/OciDriver.applyLimit.phpt +++ b/tests/Database/Drivers/OciDriver.applyLimit.phpt @@ -1,40 +1,43 @@ getDatabaseEngine(); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 20); +$engine->applyLimit($query, 10, 20); Assert::same('SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (SELECT 1 FROM t) t WHERE ROWNUM <= 30) WHERE "__rnum" > 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 0, 20); +$engine->applyLimit($query, 0, 20); Assert::same('SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (SELECT 1 FROM t) t WHERE ROWNUM <= 20) WHERE "__rnum" > 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT * FROM (SELECT 1 FROM t) WHERE ROWNUM <= 10', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, null, 20); +$engine->applyLimit($query, null, 20); Assert::same('SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (SELECT 1 FROM t) t ) WHERE "__rnum" > 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT * FROM (SELECT 1 FROM t) WHERE ROWNUM <= 10', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); diff --git a/tests/Database/Drivers/OdbcDriver.applyLimit.phpt b/tests/Database/Drivers/OdbcDriver.applyLimit.phpt index b40e3f03e..157250bd0 100644 --- a/tests/Database/Drivers/OdbcDriver.applyLimit.phpt +++ b/tests/Database/Drivers/OdbcDriver.applyLimit.phpt @@ -1,60 +1,63 @@ getDatabaseEngine(); -$driver = new Nette\Database\Drivers\OdbcDriver; - -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, 10, 20); + $engine->applyLimit($query, 10, 20); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, 0, 20); + $engine->applyLimit($query, 0, 20); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT TOP 10 1 FROM t', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, 20); + $engine->applyLimit($query, null, 20); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT TOP 10 1 FROM t', $query); $query = ' select distinct 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same(' select distinct TOP 10 1 FROM t', $query); $query = 'UPDATE t SET'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('UPDATE TOP 10 t SET', $query); $query = 'DELETE FROM t SET'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('DELETE TOP 10 FROM t SET', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SET FROM t'; - $driver->applyLimit($query, 10, null); + $engine->applyLimit($query, 10, null); }, Nette\InvalidArgumentException::class, 'SQL query must begin with SELECT, UPDATE or DELETE command.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\NotSupportedException::class, 'Offset is not supported by this database.'); diff --git a/tests/Database/Drivers/PgSqlDriver.applyLimit.phpt b/tests/Database/Drivers/PgSqlDriver.applyLimit.phpt index 6516e93d6..c1948c14e 100644 --- a/tests/Database/Drivers/PgSqlDriver.applyLimit.phpt +++ b/tests/Database/Drivers/PgSqlDriver.applyLimit.phpt @@ -1,40 +1,43 @@ getDatabaseEngine(); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 20); +$engine->applyLimit($query, 10, 20); Assert::same('SELECT 1 FROM t LIMIT 10 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 0, 20); +$engine->applyLimit($query, 0, 20); Assert::same('SELECT 1 FROM t LIMIT 0 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT 1 FROM t LIMIT 10', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, null, 20); +$engine->applyLimit($query, null, 20); Assert::same('SELECT 1 FROM t OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT 1 FROM t LIMIT 10', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); diff --git a/tests/Database/Drivers/PgSqlDriver.formatLike.phpt b/tests/Database/Drivers/PgSqlDriver.formatLike.phpt index 2e85ec7bb..44f77eb9f 100644 --- a/tests/Database/Drivers/PgSqlDriver.formatLike.phpt +++ b/tests/Database/Drivers/PgSqlDriver.formatLike.phpt @@ -13,30 +13,30 @@ require __DIR__ . '/../../bootstrap.php'; $connection = connectToDB()->getConnection(); $tests = function ($connection) { - $driver = $connection->getDriver(); + $engine = $connection->getDatabaseEngine(); - Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField()); - Assert::true($connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField()); + Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); + Assert::true($connection->query("SELECT 'AA_BB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); - Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A%B', 0)))->fetchField()); - Assert::true($connection->query("SELECT 'AA%BB' LIKE", $connection::literal($driver->formatLike('A%B', 0)))->fetchField()); + Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A%B', 0)))->fetchField()); + Assert::true($connection->query("SELECT 'AA%BB' LIKE", $connection::literal($engine->formatLike('A%B', 0)))->fetchField()); - Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike("A'B", 0)))->fetchField()); - Assert::true($connection->query("SELECT 'AA''BB' LIKE", $connection::literal($driver->formatLike("A'B", 0)))->fetchField()); + Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike("A'B", 0)))->fetchField()); + Assert::true($connection->query("SELECT 'AA''BB' LIKE", $connection::literal($engine->formatLike("A'B", 0)))->fetchField()); - Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField()); - Assert::true($connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField()); + Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A"B', 0)))->fetchField()); + Assert::true($connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($engine->formatLike('A"B', 0)))->fetchField()); }; -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); $connection->query('SET escape_string_warning TO off'); // do not log warnings $connection->query('SET standard_conforming_strings TO on'); $tests($connection); -Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\\B', 0)))->fetchField()); -Assert::true($connection->query("SELECT 'AA\\BB' LIKE", $connection::literal($driver->formatLike('A\\B', 0)))->fetchField()); +Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\\B', 0)))->fetchField()); +Assert::true($connection->query("SELECT 'AA\\BB' LIKE", $connection::literal($engine->formatLike('A\\B', 0)))->fetchField()); $connection->query('SET standard_conforming_strings TO off'); $tests($connection); -Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\\B', 0)))->fetchField()); -Assert::true($connection->query("SELECT 'AA\\\\BB' LIKE", $connection::literal($driver->formatLike('A\\B', 0)))->fetchField()); +Assert::false($connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\\B', 0)))->fetchField()); +Assert::true($connection->query("SELECT 'AA\\\\BB' LIKE", $connection::literal($engine->formatLike('A\\B', 0)))->fetchField()); diff --git a/tests/Database/Drivers/SqliteDriver.applyLimit.phpt b/tests/Database/Drivers/SqliteDriver.applyLimit.phpt index 662cb5d76..28bdc6c96 100644 --- a/tests/Database/Drivers/SqliteDriver.applyLimit.phpt +++ b/tests/Database/Drivers/SqliteDriver.applyLimit.phpt @@ -1,40 +1,44 @@ getConnection(); +$engine = $connection->getDatabaseEngine(); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 20); +$engine->applyLimit($query, 10, 20); Assert::same('SELECT 1 FROM t LIMIT 10 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 0, 20); +$engine->applyLimit($query, 0, 20); Assert::same('SELECT 1 FROM t LIMIT 0 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT 1 FROM t LIMIT 10', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, null, 20); +$engine->applyLimit($query, null, 20); Assert::same('SELECT 1 FROM t LIMIT -1 OFFSET 20', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT 1 FROM t LIMIT 10', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); diff --git a/tests/Database/Drivers/SqliteDriver.formatLike.phpt b/tests/Database/Drivers/SqliteDriver.formatLike.phpt index 2b2443957..0f50071fe 100644 --- a/tests/Database/Drivers/SqliteDriver.formatLike.phpt +++ b/tests/Database/Drivers/SqliteDriver.formatLike.phpt @@ -11,22 +11,22 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $connection = connectToDB()->getConnection(); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA_BB' LIKE", $connection::literal($engine->formatLike('A_B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A%B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA%BB' LIKE", $connection::literal($driver->formatLike('A%B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A%B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA%BB' LIKE", $connection::literal($engine->formatLike('A%B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike("A'B", 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA''BB' LIKE", $connection::literal($driver->formatLike("A'B", 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike("A'B", 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA''BB' LIKE", $connection::literal($engine->formatLike("A'B", 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A"B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA\"BB' LIKE", $connection::literal($engine->formatLike('A"B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA\\BB' LIKE", $connection::literal($driver->formatLike('A\B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA\\BB' LIKE", $connection::literal($engine->formatLike('A\B', 0)))->fetchField()); -Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)))->fetchField()); -Assert::same(1, $connection->query("SELECT 'AA\\%BB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)))->fetchField()); +Assert::same(0, $connection->query("SELECT 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\%B', 0)))->fetchField()); +Assert::same(1, $connection->query("SELECT 'AA\\%BB' LIKE", $connection::literal($engine->formatLike('A\%B', 0)))->fetchField()); diff --git a/tests/Database/Drivers/SqlsrvDriver.applyLimit.phpt b/tests/Database/Drivers/SqlsrvDriver.applyLimit.phpt index 3a06219af..78a31e591 100644 --- a/tests/Database/Drivers/SqlsrvDriver.applyLimit.phpt +++ b/tests/Database/Drivers/SqlsrvDriver.applyLimit.phpt @@ -1,42 +1,45 @@ getDatabaseEngine(); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 20); +$engine->applyLimit($query, 10, 20); Assert::same('SELECT 1 FROM t OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 0, 20); +$engine->applyLimit($query, 0, 20); Assert::same('SELECT 1 FROM t OFFSET 20 ROWS FETCH NEXT 0 ROWS ONLY', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, 0); +$engine->applyLimit($query, 10, 0); Assert::same('SELECT 1 FROM t OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, null, 20); +$engine->applyLimit($query, null, 20); Assert::same('SELECT 1 FROM t OFFSET 20 ROWS FETCH NEXT 0 ROWS ONLY', $query); $query = 'SELECT 1 FROM t'; -$driver->applyLimit($query, 10, null); +$engine->applyLimit($query, 10, null); Assert::same('SELECT 1 FROM t OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $query); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, -1, null); + $engine->applyLimit($query, -1, null); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); -Assert::exception(function () use ($driver) { +Assert::exception(function () use ($engine) { $query = 'SELECT 1 FROM t'; - $driver->applyLimit($query, null, -1); + $engine->applyLimit($query, null, -1); }, Nette\InvalidArgumentException::class, 'Negative offset or limit.'); diff --git a/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt b/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt index cd5ccc3f1..682430aac 100644 --- a/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt +++ b/tests/Database/Drivers/SqlsrvDriver.formatLike.phpt @@ -11,25 +11,25 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; $connection = connectToDB()->getConnection(); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA_BB' LIKE", $connection::literal($driver->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA_BB' LIKE", $connection::literal($engine->formatLike('A_B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA%BB' LIKE", $connection::literal($driver->formatLike('A%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA%BB' LIKE", $connection::literal($engine->formatLike('A%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike("A'B", 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA''BB' LIKE", $connection::literal($driver->formatLike("A'B", 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike("A'B", 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA''BB' LIKE", $connection::literal($engine->formatLike("A'B", 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A"B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA\"BB' LIKE", $connection::literal($driver->formatLike('A"B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A"B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA\"BB' LIKE", $connection::literal($engine->formatLike('A"B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA\\BB' LIKE", $connection::literal($driver->formatLike('A\B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA\\BB' LIKE", $connection::literal($engine->formatLike('A\B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA\\%BB' LIKE", $connection::literal($driver->formatLike('A\%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A\%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA\\%BB' LIKE", $connection::literal($engine->formatLike('A\%B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($driver->formatLike('A[a-z]B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); -Assert::same(1, $connection->query("SELECT CASE WHEN 'AA[a-z]BB' LIKE", $connection::literal($driver->formatLike('A[a-z]B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(0, $connection->query("SELECT CASE WHEN 'AAxBB' LIKE", $connection::literal($engine->formatLike('A[a-z]B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); +Assert::same(1, $connection->query("SELECT CASE WHEN 'AA[a-z]BB' LIKE", $connection::literal($engine->formatLike('A[a-z]B', 0)), 'THEN 1 ELSE 0 END AS col')->fetchField()); diff --git a/tests/Database/Reflection.postgre.10.phpt b/tests/Database/Engine.postgre.10.phpt similarity index 83% rename from tests/Database/Reflection.postgre.10.phpt rename to tests/Database/Engine.postgre.10.phpt index 2d9718ac3..6d4519adc 100644 --- a/tests/Database/Reflection.postgre.10.phpt +++ b/tests/Database/Engine.postgre.10.phpt @@ -45,17 +45,17 @@ test('SERIAL and IDENTITY imply autoIncrement on primary keys', function () use CREATE TABLE "reflection_10"."identity_by_default_pk" ("id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY); ')); - $driver = $connection->getDriver(); + $engine = $connection->getDatabaseEngine(); $connection->query('SET search_path TO reflection_10'); $columns = [ - 'serial' => shortInfo($driver->getColumns('serial')), - 'serial_pk' => shortInfo($driver->getColumns('serial_pk')), - 'identity_always' => shortInfo($driver->getColumns('identity_always')), - 'identity_always_pk' => shortInfo($driver->getColumns('identity_always_pk')), - 'identity_by_default' => shortInfo($driver->getColumns('identity_by_default')), - 'identity_by_default_pk' => shortInfo($driver->getColumns('identity_by_default_pk')), + 'serial' => shortInfo($engine->getColumns('serial')), + 'serial_pk' => shortInfo($engine->getColumns('serial_pk')), + 'identity_always' => shortInfo($engine->getColumns('identity_always')), + 'identity_always_pk' => shortInfo($engine->getColumns('identity_always_pk')), + 'identity_by_default' => shortInfo($engine->getColumns('identity_by_default')), + 'identity_by_default_pk' => shortInfo($engine->getColumns('identity_by_default_pk')), ]; Assert::same([ @@ -111,18 +111,18 @@ test('Materialized view columns', function () use ($connection) { CREATE MATERIALIZED VIEW "reflection_10"."source_mt" AS SELECT "name", "id" FROM "reflection_10"."source"; ')); - $driver = $connection->getDriver(); + $engine = $connection->getDatabaseEngine(); $connection->query('SET search_path TO reflection_10'); Assert::same([ ['name' => 'source', 'view' => false, 'fullName' => 'reflection_10.source'], ['name' => 'source_mt', 'view' => true, 'fullName' => 'reflection_10.source_mt'], - ], $driver->getTables()); + ], $engine->getTables()); Assert::same( ['name', 'id'], - array_column($driver->getColumns('source_mt'), 'name'), + array_column($engine->getColumns('source_mt'), 'name'), ); }); @@ -140,22 +140,22 @@ test('Partitioned table', function () use ($connection) { CREATE TABLE "reflection_10"."part_1" PARTITION OF "reflection_10"."parted" FOR VALUES FROM (1) TO (10); ')); - $driver = $connection->getDriver(); + $engine = $connection->getDatabaseEngine(); $connection->query('SET search_path TO reflection_10'); Assert::same([ ['name' => 'part_1', 'view' => false, 'fullName' => 'reflection_10.part_1'], ['name' => 'parted', 'view' => false, 'fullName' => 'reflection_10.parted'], - ], $driver->getTables()); + ], $engine->getTables()); - Assert::same(['id', 'value'], array_column($driver->getColumns('parted'), 'name')); - Assert::same(['id', 'value'], array_column($driver->getColumns('part_1'), 'name')); + Assert::same(['id', 'value'], array_column($engine->getColumns('parted'), 'name')); + Assert::same(['id', 'value'], array_column($engine->getColumns('part_1'), 'name')); Assert::same([[ 'name' => 'parted_pkey', 'unique' => true, 'primary' => true, 'columns' => ['id'], - ]], $driver->getIndexes('parted')); + ]], $engine->getIndexes('parted')); }); diff --git a/tests/Database/Reflection.postgre.phpt b/tests/Database/Engine.postgre.phpt similarity index 69% rename from tests/Database/Reflection.postgre.phpt rename to tests/Database/Engine.postgre.phpt index 53393629a..9ca883377 100644 --- a/tests/Database/Reflection.postgre.phpt +++ b/tests/Database/Engine.postgre.phpt @@ -43,26 +43,26 @@ test('Tables in schema', function () use ($connection) { ALTER TABLE "two"."slave" ADD CONSTRAINT "two_slave_fk" FOREIGN KEY ("two_id") REFERENCES "two"."master"("two_id"); ')); - $driver = $connection->getDriver(); + $engine = $connection->getDatabaseEngine(); // Reflection for tables with the same name but different schema $connection->query('SET search_path TO one, two'); - Assert::same(['master', 'slave'], names($driver->getTables())); - Assert::same(['one_id'], names($driver->getColumns('master'))); - Assert::same(['one_master_pkey'], names($driver->getIndexes('master'))); - Assert::same(['one_slave_fk'], names($driver->getForeignKeys('slave'))); + Assert::same(['master', 'slave'], names($engine->getTables())); + Assert::same(['one_id'], names($engine->getColumns('master'))); + Assert::same(['one_master_pkey'], names($engine->getIndexes('master'))); + Assert::same(['one_slave_fk'], names($engine->getForeignKeys('slave'))); $connection->query('SET search_path TO two, one'); - Assert::same(['master', 'slave'], names($driver->getTables())); - Assert::same(['two_id'], names($driver->getColumns('master'))); - Assert::same(['two_master_pkey'], names($driver->getIndexes('master'))); - Assert::same(['two_slave_fk'], names($driver->getForeignKeys('slave'))); + Assert::same(['master', 'slave'], names($engine->getTables())); + Assert::same(['two_id'], names($engine->getColumns('master'))); + Assert::same(['two_master_pkey'], names($engine->getIndexes('master'))); + Assert::same(['two_slave_fk'], names($engine->getForeignKeys('slave'))); // Reflection for FQN - Assert::same(['one_id'], names($driver->getColumns('one.master'))); - Assert::same(['one_master_pkey'], names($driver->getIndexes('one.master'))); - $foreign = $driver->getForeignKeys('one.slave'); + Assert::same(['one_id'], names($engine->getColumns('one.master'))); + Assert::same(['one_master_pkey'], names($engine->getIndexes('one.master'))); + $foreign = $engine->getForeignKeys('one.slave'); Assert::same([ 'name' => 'one_slave_fk', 'local' => 'one_id', @@ -74,7 +74,7 @@ test('Tables in schema', function () use ($connection) { // Limit foreign keys for current schemas only $connection->query('ALTER TABLE "one"."slave" ADD CONSTRAINT "one_two_fk" FOREIGN KEY ("one_id") REFERENCES "two"."master"("two_id")'); $connection->query('SET search_path TO one'); - Assert::same(['one_slave_fk'], names($driver->getForeignKeys('slave'))); + Assert::same(['one_slave_fk'], names($engine->getForeignKeys('slave'))); $connection->query('SET search_path TO one, two'); - Assert::same(['one_slave_fk', 'one_two_fk'], names($driver->getForeignKeys('slave'))); + Assert::same(['one_slave_fk', 'one_two_fk'], names($engine->getForeignKeys('slave'))); }); diff --git a/tests/Database/Reflection.driver.phpt b/tests/Database/Engine.reflection.phpt similarity index 94% rename from tests/Database/Reflection.driver.phpt rename to tests/Database/Engine.reflection.phpt index 0098c5777..ea07bcc63 100644 --- a/tests/Database/Reflection.driver.phpt +++ b/tests/Database/Engine.reflection.phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -18,12 +18,12 @@ $connection = $explorer->getConnection(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql"); -$driver = $connection->getDriver(); -$tables = $driver->getTables(); +$engine = $connection->getDatabaseEngine(); +$tables = $engine->getTables(); $tables = array_filter($tables, fn($t) => in_array($t['name'], ['author', 'book', 'book_tag', 'tag'], true)); usort($tables, fn($a, $b) => strcmp($a['name'], $b['name'])); -if ($driver->isSupported(Driver::SupportSchema)) { +if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( [ ['name' => 'author', 'view' => false, 'fullName' => 'public.author'], @@ -43,7 +43,7 @@ if ($driver->isSupported(Driver::SupportSchema)) { } -$columns = $driver->getColumns('author'); +$columns = $engine->getColumns('author'); array_walk($columns, function (&$item) { Assert::type('array', $item['vendor']); unset($item['vendor']); @@ -128,7 +128,7 @@ switch ($driverName) { Assert::same($expectedColumns, $columns); -$indexes = $driver->getIndexes('book_tag'); +$indexes = $engine->getIndexes('book_tag'); switch ($driverName) { case 'pgsql': Assert::same([ diff --git a/tests/Database/Explorer/Explorer.backjoin.phpt b/tests/Database/Explorer/Explorer.backjoin.phpt index a466b3404..73f982dd0 100644 --- a/tests/Database/Explorer/Explorer.backjoin.phpt +++ b/tests/Database/Explorer/Explorer.backjoin.phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; @@ -16,7 +16,7 @@ $explorer = connectToDB(); $connection = $explorer->getConnection(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); test('', function () use ($explorer) { @@ -39,10 +39,10 @@ test('', function () use ($explorer) { }); -test('', function () use ($explorer, $driver) { +test('', function () use ($explorer, $engine) { $authorsSelection = $explorer->table('author')->where(':book.translator_id IS NOT NULL')->wherePrimary(12); - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( reformat('SELECT [author].* FROM [author] LEFT JOIN [public].[book] [book] ON [author].[id] = [book].[author_id] WHERE ([book].[translator_id] IS NOT NULL) AND ([author].[id] = ?)'), $authorsSelection->getSql(), diff --git a/tests/Database/Explorer/Explorer.join-condition.phpt b/tests/Database/Explorer/Explorer.join-condition.phpt index 34af228b9..1e92b43e6 100644 --- a/tests/Database/Explorer/Explorer.join-condition.phpt +++ b/tests/Database/Explorer/Explorer.join-condition.phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; @@ -16,9 +16,9 @@ $explorer = connectToDB(); $connection = $explorer->getConnection(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$driver = $connection->getDriver(); -test('', function () use ($explorer, $driver) { - $schema = $driver->isSupported(Driver::SupportSchema) +$engine = $connection->getDatabaseEngine(); +test('', function () use ($explorer, $engine) { + $schema = $engine->isSupported(Engine::SupportSchema) ? '[public].' : ''; $sql = $explorer->table('book')->joinWhere('translator', 'translator.name', 'Geek')->select('book.*')->getSql(); @@ -29,7 +29,7 @@ test('', function () use ($explorer, $driver) { ), $sql); }); -test('', function () use ($explorer, $driver) { +test('', function () use ($explorer, $engine) { $sql = $explorer->table('tag') ->select('tag.name, COUNT(:book_tag.book.id) AS count_of_next_volume_written_by_younger_author') ->joinWhere(':book_tag.book.author', ':book_tag.book.author.born < next_volume_author.born') @@ -37,7 +37,7 @@ test('', function () use ($explorer, $driver) { ->where('tag.name', 'PHP') ->group('tag.name') ->getSql(); - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( reformat( 'SELECT [tag].[name], COUNT([book].[id]) AS [count_of_next_volume_written_by_younger_author] FROM [tag] ' . diff --git a/tests/Database/Explorer/Explorer.join.phpt b/tests/Database/Explorer/Explorer.join.phpt index 53d26e911..604081f3b 100644 --- a/tests/Database/Explorer/Explorer.join.phpt +++ b/tests/Database/Explorer/Explorer.join.phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; @@ -16,7 +16,7 @@ $explorer = connectToDB(); $connection = $explorer->getConnection(); Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql"); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); test('', function () use ($explorer) { @@ -34,10 +34,10 @@ test('', function () use ($explorer) { }); -test('', function () use ($explorer, $driver) { +test('', function () use ($explorer, $engine) { $joinSql = $explorer->table('book_tag')->where('book_id', 1)->select('tag.*')->getSql(); - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( reformat('SELECT [tag].* FROM [book_tag] LEFT JOIN [public].[tag] [tag] ON [book_tag].[tag_id] = [tag].[id] WHERE ([book_id] = ?)'), $joinSql, @@ -51,10 +51,10 @@ test('', function () use ($explorer, $driver) { }); -test('', function () use ($explorer, $driver) { +test('', function () use ($explorer, $engine) { $joinSql = $explorer->table('book_tag')->where('book_id', 1)->select('Tag.id')->getSql(); - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( reformat('SELECT [Tag].[id] FROM [book_tag] LEFT JOIN [public].[tag] [Tag] ON [book_tag].[tag_id] = [Tag].[id] WHERE ([book_id] = ?)'), $joinSql, diff --git a/tests/Database/Explorer/SqlBuilder.addAlias().phpt b/tests/Database/Explorer/SqlBuilder.addAlias().phpt index f3fbd4a06..3b253b6da 100644 --- a/tests/Database/Explorer/SqlBuilder.addAlias().phpt +++ b/tests/Database/Explorer/SqlBuilder.addAlias().phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Nette\Database\Table\SqlBuilder; use Tester\Assert; @@ -32,11 +32,11 @@ class SqlBuilderMock extends SqlBuilder } } -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); -test('test duplicated table names throw exception', function () use ($explorer, $driver) { - $authorTable = ($driver->isSupported(Driver::SupportSchema) ? 'public.' : '') . 'author'; +test('test duplicated table names throw exception', function () use ($explorer, $engine) { + $authorTable = ($engine->isSupported(Engine::SupportSchema) ? 'public.' : '') . 'author'; $sqlBuilder = new SqlBuilderMock($authorTable, $explorer); $sqlBuilder->addAlias(':book(translator)', 'book1'); $sqlBuilder->addAlias(':book:book_tag', 'book2'); @@ -73,7 +73,7 @@ test('test duplicated table names throw exception', function () use ($explorer, }); -test('test same table chain with another alias', function () use ($explorer, $driver) { +test('test same table chain with another alias', function () use ($explorer, $engine) { $sqlBuilder = new SqlBuilderMock('author', $explorer); $sqlBuilder->addAlias(':book(translator)', 'translated_book'); $sqlBuilder->addAlias(':book(translator)', 'translated_book2'); @@ -90,8 +90,8 @@ test('test same table chain with another alias', function () use ($explorer, $dr }); -test('test nested alias', function () use ($explorer, $driver) { - $sqlBuilder = $driver->isSupported(Driver::SupportSchema) +test('test nested alias', function () use ($explorer, $engine) { + $sqlBuilder = $engine->isSupported(Engine::SupportSchema) ? new SqlBuilderMock('public.author', $explorer) : new SqlBuilderMock('author', $explorer); $sqlBuilder->addAlias(':book(translator)', 'translated_book'); @@ -100,7 +100,7 @@ test('test nested alias', function () use ($explorer, $driver) { $joins = []; $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( 'LEFT JOIN book translated_book ON author.id = translated_book.translator_id ' . 'LEFT JOIN public.book next ON translated_book.next_volume = next.id', diff --git a/tests/Database/Explorer/SqlBuilder.addWhere().phpt b/tests/Database/Explorer/SqlBuilder.addWhere().phpt index 6dd477207..0b4b24e64 100644 --- a/tests/Database/Explorer/SqlBuilder.addWhere().phpt +++ b/tests/Database/Explorer/SqlBuilder.addWhere().phpt @@ -8,7 +8,7 @@ declare(strict_types=1); use Nette\Database\Conventions\DiscoveredConventions; -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Nette\Database\SqlLiteral; use Nette\Database\Table\SqlBuilder; use Tester\Assert; @@ -83,7 +83,7 @@ test('test more ActiveRow as a parameter', function () use ($explorer) { test('test Selection with parameters as a parameter', function () use ($explorer) { $sqlBuilder = new SqlBuilder('book', $explorer); $sqlBuilder->addWhere('id', $explorer->table('book')->having('COUNT(:book_tag.tag_id) >', 1)); - $schemaSupported = $explorer->getConnection()->getDriver()->isSupported(Driver::SupportSchema); + $schemaSupported = $explorer->getConnection()->getDatabaseEngine()->isSupported(Engine::SupportSchema); Assert::equal(reformat([ 'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))', 'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book] LEFT JOIN ' . ($schemaSupported ? '[public].[book_tag] ' : '') . '[book_tag] ON [book].[id] = [book_tag].[book_id] HAVING COUNT([book_tag].[tag_id]) > ?))', diff --git a/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt b/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt index cb0d83ff0..17e6909e7 100644 --- a/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt +++ b/tests/Database/Explorer/SqlBuilder.parseJoinConditions().phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Nette\Database\Table\SqlBuilder; use Tester\Assert; @@ -44,7 +44,7 @@ class SqlBuilderMock extends SqlBuilder } } -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); test('test circular reference', function () use ($explorer) { $sqlBuilder = new SqlBuilderMock('author', $explorer); @@ -75,7 +75,7 @@ test('test circular reference', function () use ($explorer) { ); }); -test('', function () use ($explorer, $driver) { +test('', function () use ($explorer, $engine) { $sqlBuilder = new SqlBuilderMock('author', $explorer); $sqlBuilder->addJoinCondition(':book(translator)', ':book(translator).id > ?', 2); $sqlBuilder->addJoinCondition(':book(translator):book_tag_alt', ':book(translator):book_tag_alt.state ?', 'private'); @@ -83,7 +83,7 @@ test('', function () use ($explorer, $driver) { $leftJoinConditions = $sqlBuilder->parseJoinConditions($joins, $sqlBuilder->buildJoinConditions()); $join = $sqlBuilder->buildQueryJoins($joins, $leftJoinConditions); - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( 'LEFT JOIN book ON author.id = book.translator_id AND (book.id > ?) ' . 'LEFT JOIN public.book_tag_alt book_tag_alt ON book.id = book_tag_alt.book_id AND (book_tag_alt.state = ?)', diff --git a/tests/Database/Explorer/SqlBuilder.parseJoins().phpt b/tests/Database/Explorer/SqlBuilder.parseJoins().phpt index 847f32ec4..c77b37f44 100644 --- a/tests/Database/Explorer/SqlBuilder.parseJoins().phpt +++ b/tests/Database/Explorer/SqlBuilder.parseJoins().phpt @@ -8,7 +8,7 @@ declare(strict_types=1); use Nette\Database\Conventions\DiscoveredConventions; -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Nette\Database\Table\SqlBuilder; use Tester\Assert; @@ -37,7 +37,7 @@ class SqlBuilderMock extends SqlBuilder $structure = $explorer->getStructure(); $conventions = new DiscoveredConventions($structure); $sqlBuilder = new SqlBuilderMock('nUsers', $explorer); -$driver = $connection->getDriver(); +$engine = $connection->getDatabaseEngine(); $joins = []; @@ -46,9 +46,9 @@ $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); Assert::same('WHERE priorit.id IS NULL', $query); -$tables = $connection->getDriver()->getTables(); +$tables = $connection->getDatabaseEngine()->getTables(); if (!in_array($tables[0]['name'], ['npriorities', 'ntopics', 'nusers', 'nusers_ntopics', 'nusers_ntopics_alt'], true)) { - if ($driver->isSupported(Driver::SupportSchema)) { + if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( 'LEFT JOIN public.nUsers_nTopics nusers_ntopics ON nUsers.nUserId = nusers_ntopics.nUserId ' . 'LEFT JOIN public.nTopics topic ON nusers_ntopics.nTopicId = topic.nTopicId ' . @@ -91,7 +91,7 @@ Assert::same( ); -$sqlBuilder = $driver->isSupported(Driver::SupportSchema) +$sqlBuilder = $engine->isSupported(Engine::SupportSchema) ? new SqlBuilderMock('public.book', $explorer) : new SqlBuilderMock('book', $explorer); @@ -101,7 +101,7 @@ $sqlBuilder->parseJoins($joins, $query); $join = $sqlBuilder->buildQueryJoins($joins); Assert::same('WHERE book_ref.translator_id IS NULL AND book_ref_ref.translator_id IS NULL', $query); -if ($driver->isSupported(Driver::SupportSchema)) { +if ($engine->isSupported(Engine::SupportSchema)) { Assert::same( 'LEFT JOIN public.book book_ref ON book.id = book_ref.next_volume ' . 'LEFT JOIN public.book book_ref_ref ON book_ref.id = book_ref_ref.next_volume', diff --git a/tests/Database/Explorer/bugs/view.bug.phpt b/tests/Database/Explorer/bugs/view.bug.phpt index 0a555757b..0837c9d93 100644 --- a/tests/Database/Explorer/bugs/view.bug.phpt +++ b/tests/Database/Explorer/bugs/view.bug.phpt @@ -23,8 +23,8 @@ test('', function () use ($explorer) { }); test('', function () use ($connection) { - $driver = $connection->getDriver(); - $columns = $driver->getColumns('books_view'); + $engine = $connection->getDatabaseEngine(); + $columns = $engine->getColumns('books_view'); $columnsNames = array_map(fn($item) => $item['name'], $columns); Assert::same(['id', 'author_id', 'translator_id', 'title', 'next_volume'], $columnsNames); }); diff --git a/tests/Database/Reflection.phpt b/tests/Database/Reflection.phpt index 80fa8ab6b..dc06d824f 100644 --- a/tests/Database/Reflection.phpt +++ b/tests/Database/Reflection.phpt @@ -7,7 +7,7 @@ declare(strict_types=1); -use Nette\Database\Driver; +use Nette\Database\Drivers\Engine; use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -17,7 +17,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName $reflection = $connection->getReflection(); -$schemaSupported = $connection->getDriver()->isSupported(Driver::SupportSchema); +$schemaSupported = $connection->getDatabaseEngine()->isSupported(Engine::SupportSchema); // table names $tableNames = array_keys($reflection->tables); diff --git a/tests/Database/Row.phpt b/tests/Database/Row.phpt index f9f800c5d..aff5d3a1f 100644 --- a/tests/Database/Row.phpt +++ b/tests/Database/Row.phpt @@ -14,7 +14,7 @@ require __DIR__ . '/../bootstrap.php'; $connection = connectToDB()->getConnection(); test('numeric field', function () use ($connection) { - $row = $connection->fetch("SELECT 123 AS {$connection->getDriver()->delimite('123')}, NULL as nullcol"); + $row = $connection->fetch("SELECT 123 AS {$connection->getDatabaseEngine()->delimite('123')}, NULL as nullcol"); Assert::same(123, $row->{123}); Assert::same(123, $row->{'123'}); Assert::true(isset($row->{123})); diff --git a/tests/Database/Structure.phpt b/tests/Database/Structure.phpt index 9e585e4c0..b9e2b559a 100644 --- a/tests/Database/Structure.phpt +++ b/tests/Database/Structure.phpt @@ -30,7 +30,7 @@ class StructureMock extends Structure class StructureTestCase extends TestCase { private Nette\Database\Connection $connection; - private Nette\Database\Driver $driver; + private Nette\Database\Drivers\Engine $engine; private Nette\Caching\Storage $storage; private Structure $structure; @@ -38,47 +38,47 @@ class StructureTestCase extends TestCase protected function setUp() { parent::setUp(); - $this->driver = Mockery::mock(Nette\Database\Driver::class); + $this->engine = Mockery::mock(Nette\Database\Drivers\Engine::class); $this->connection = Mockery::mock(Nette\Database\Connection::class); $this->storage = Mockery::mock(Nette\Caching\Storage::class); $this->connection->shouldReceive('getDsn')->once()->andReturn(''); - $this->connection->shouldReceive('getDriver')->once()->andReturn($this->driver); - $this->driver->shouldReceive('getTables')->once()->andReturn([ + $this->connection->shouldReceive('getDatabaseEngine')->once()->andReturn($this->engine); + $this->engine->shouldReceive('getTables')->once()->andReturn([ ['name' => 'authors', 'view' => false], ['name' => 'Books', 'view' => false], ['name' => 'tags', 'view' => false], ['name' => 'books_x_tags', 'view' => false], ['name' => 'books_view', 'view' => true], ]); - $this->driver->shouldReceive('getColumns')->with('authors')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('authors')->once()->andReturn([ ['name' => 'id', 'primary' => true, 'autoIncrement' => true, 'vendor' => ['sequence' => '"public"."authors_id_seq"']], ['name' => 'name', 'primary' => false, 'autoIncrement' => false, 'vendor' => []], ]); - $this->driver->shouldReceive('getColumns')->with('Books')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('Books')->once()->andReturn([ ['name' => 'id', 'primary' => true, 'autoIncrement' => true, 'vendor' => ['sequence' => '"public"."Books_id_seq"']], ['name' => 'title', 'primary' => false, 'autoIncrement' => false, 'vendor' => []], ]); - $this->driver->shouldReceive('getColumns')->with('tags')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('tags')->once()->andReturn([ ['name' => 'id', 'primary' => true, 'autoIncrement' => false, 'vendor' => []], ['name' => 'name', 'primary' => false, 'autoIncrement' => false, 'vendor' => []], ]); - $this->driver->shouldReceive('getColumns')->with('books_x_tags')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('books_x_tags')->once()->andReturn([ ['name' => 'book_id', 'primary' => true, 'autoIncrement' => false, 'vendor' => []], ['name' => 'tag_id', 'primary' => true, 'autoIncrement' => false, 'vendor' => []], ]); - $this->driver->shouldReceive('getColumns')->with('books_view')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('books_view')->once()->andReturn([ ['name' => 'id', 'primary' => false, 'autoIncrement' => false, 'vendor' => []], ['name' => 'title', 'primary' => false, 'autoIncrement' => false, 'vendor' => []], ]); - $this->connection->shouldReceive('getDriver')->times(4)->andReturn($this->driver); - $this->driver->shouldReceive('getForeignKeys')->with('authors')->once()->andReturn([]); - $this->driver->shouldReceive('getForeignKeys')->with('Books')->once()->andReturn([ + $this->connection->shouldReceive('getDatabaseEngine')->times(4)->andReturn($this->engine); + $this->engine->shouldReceive('getForeignKeys')->with('authors')->once()->andReturn([]); + $this->engine->shouldReceive('getForeignKeys')->with('Books')->once()->andReturn([ ['local' => 'author_id', 'table' => 'authors', 'foreign' => 'id', 'name' => 'authors_fk1'], ['local' => 'translator_id', 'table' => 'authors', 'foreign' => 'id', 'name' => 'authors_fk2'], ]); - $this->driver->shouldReceive('getForeignKeys')->with('tags')->once()->andReturn([]); - $this->driver->shouldReceive('getForeignKeys')->with('books_x_tags')->once()->andReturn([ + $this->engine->shouldReceive('getForeignKeys')->with('tags')->once()->andReturn([]); + $this->engine->shouldReceive('getForeignKeys')->with('books_x_tags')->once()->andReturn([ ['local' => 'book_id', 'table' => 'Books', 'foreign' => 'id', 'name' => 'books_x_tags_fk1'], ['local' => 'tag_id', 'table' => 'tags', 'foreign' => 'id', 'name' => 'books_x_tags_fk2'], ]); @@ -132,9 +132,9 @@ class StructureTestCase extends TestCase public function testGetPrimaryKeySequence() { - $this->connection->shouldReceive('getDriver')->times(4)->andReturn($this->driver); - $this->driver->shouldReceive('isSupported')->with('sequence')->once()->andReturn(false); - $this->driver->shouldReceive('isSupported')->with('sequence')->times(3)->andReturn(true); + $this->connection->shouldReceive('getDatabaseEngine')->times(4)->andReturn($this->engine); + $this->engine->shouldReceive('isSupported')->with('sequence')->once()->andReturn(false); + $this->engine->shouldReceive('isSupported')->with('sequence')->times(3)->andReturn(true); Assert::null($this->structure->getPrimaryKeySequence('Authors')); Assert::same('"public"."authors_id_seq"', $this->structure->getPrimaryKeySequence('Authors')); diff --git a/tests/Database/Structure.schemas.phpt b/tests/Database/Structure.schemas.phpt index 0a145a56c..406b47fc7 100644 --- a/tests/Database/Structure.schemas.phpt +++ b/tests/Database/Structure.schemas.phpt @@ -30,7 +30,7 @@ class StructureMock extends Structure class StructureSchemasTestCase extends TestCase { private Nette\Database\Connection $connection; - private Nette\Database\Driver $driver; + private Nette\Database\Drivers\Engine $engine; private Nette\Caching\Storage $storage; private Structure $structure; @@ -38,28 +38,28 @@ class StructureSchemasTestCase extends TestCase protected function setUp() { parent::setUp(); - $this->driver = Mockery::mock(Nette\Database\Driver::class); + $this->engine = Mockery::mock(Nette\Database\Drivers\Engine::class); $this->connection = Mockery::mock(Nette\Database\Connection::class); $this->storage = Mockery::mock(Nette\Caching\Storage::class); $this->connection->shouldReceive('getDsn')->once()->andReturn(''); - $this->connection->shouldReceive('getDriver')->once()->andReturn($this->driver); - $this->driver->shouldReceive('getTables')->once()->andReturn([ + $this->connection->shouldReceive('getDatabaseEngine')->once()->andReturn($this->engine); + $this->engine->shouldReceive('getTables')->once()->andReturn([ ['name' => 'authors', 'view' => false, 'fullName' => 'authors.authors'], ['name' => 'books', 'view' => false, 'fullName' => 'books.books'], ]); - $this->driver->shouldReceive('getColumns')->with('authors.authors')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('authors.authors')->once()->andReturn([ ['name' => 'id', 'primary' => true, 'vendor' => ['sequence' => '"authors"."authors_id_seq"']], ['name' => 'name', 'primary' => false, 'vendor' => []], ]); - $this->driver->shouldReceive('getColumns')->with('books.books')->once()->andReturn([ + $this->engine->shouldReceive('getColumns')->with('books.books')->once()->andReturn([ ['name' => 'id', 'primary' => true, 'vendor' => ['sequence' => '"books"."books_id_seq"']], ['name' => 'title', 'primary' => false, 'vendor' => []], ]); - $this->connection->shouldReceive('getDriver')->times(2)->andReturn($this->driver); - $this->driver->shouldReceive('getForeignKeys')->with('authors.authors')->once()->andReturn([]); - $this->driver->shouldReceive('getForeignKeys')->with('books.books')->once()->andReturn([ + $this->connection->shouldReceive('getDatabaseEngine')->times(2)->andReturn($this->engine); + $this->engine->shouldReceive('getForeignKeys')->with('authors.authors')->once()->andReturn([]); + $this->engine->shouldReceive('getForeignKeys')->with('books.books')->once()->andReturn([ ['local' => 'author_id', 'table' => 'authors.authors', 'foreign' => 'id', 'name' => 'authors_authors_fk1'], ['local' => 'translator_id', 'table' => 'authors.authors', 'foreign' => 'id', 'name' => 'authors_authors_fk2'], ]);