Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
52a346c
ResultSet: added fetchList() as alias for fetchFields() & shortcuts
dg Aug 28, 2024
7c4be75
github actions updated
dg Sep 2, 2024
caaaa42
cs
dg Sep 4, 2024
3a1030c
opened 4.0-dev
dg Mar 1, 2021
e67b168
readme: added jumbo
dg May 16, 2024
35cf35a
removed old Driver::SUPPORT & MySqlDriver::Error constants (BC break)
dg May 10, 2024
49c05db
deprecated methods trigger notices
dg Jan 19, 2022
0e7f616
DatabaseExtension: removed obsolete option 'reflection'
dg Aug 29, 2024
4d4ae57
Driver::getColumns() nativetype -> nativeType, autoincrement -> autoI…
dg Sep 4, 2024
c2fe331
Reflection: added 'scale' field
dg Sep 4, 2024
c26d1e1
returns date-time as immutable Nette\Database\DateTime by default (BC…
dg Aug 27, 2024
5059ce6
MySQL: convertBoolean is true by default (BC break)
dg Aug 28, 2024
923bc75
removed aliases for ISupplementalDriver, IConventions (BC break)
dg Aug 10, 2024
1727e55
removed IRow & IRowContainer (BC break)
dg Aug 10, 2024
5c5b607
removed formatLike() (BC break)
dg Sep 4, 2024
6cffe42
ConnectionPanel: refactoring, initialize($addBarPanel) is true by def…
dg Aug 27, 2024
40ab5c6
connections are always lazy (BC break)
dg Aug 29, 2024
8c86228
renamed Nette\Database\ResultSet -> Result
dg Aug 28, 2024
96c2e8a
renamed Nette\Database\Driver -> Nette\Database\Drivers\Engine (BC br…
dg Aug 28, 2024
f3e3cd9
renamed drivers to *Engine
dg Sep 3, 2024
362e62c
added new drivers
dg Aug 16, 2024
b435456
Connection: the driver is created in the constructor
dg Sep 3, 2024
e511b44
connections & engines are created by Driver
dg Sep 4, 2024
9718880
PDO replaced by Connection
dg Sep 4, 2024
b775226
added Connection::getServerVersion()
dg Aug 15, 2024
b11c0bf
added Connection::execute()
dg Sep 4, 2024
be8936f
Connection::getPdo() deprecated
dg Aug 15, 2024
0cf2662
added TypeConverter
dg Aug 17, 2024
4415f62
uses TypeConverter to convert values to PHP
dg Sep 4, 2024
bb7f7fb
added option convertDateTime
dg Sep 3, 2024
0eb80cf
added option convertDecimal & converts to int/float [Closes #257]
dg Sep 3, 2024
68f45f8
SqlsrvDriver: converts BIT to boolean (BC break)
dg Aug 17, 2024
9075da3
removed custom rowNormalizer (BC break)
dg Sep 4, 2024
4bb25d2
PDOStatement replaced by Result
dg Aug 29, 2024
1e40d23
Result::getColumnMeta is cached (ref #212)
dg Aug 15, 2024
9bc920b
try/catch checking and converting of PDOException moved to drivers
dg Sep 4, 2024
955b992
DriverException::getCode() returns driver error code instead of SQLSt…
dg Aug 27, 2024
235def4
Connection: calling query() moved here from Result
dg Sep 3, 2024
2478ffb
added Connection::getLastQuery(), Result::getQuery(), DriverException…
dg Sep 3, 2024
3cadf6e
Connection::getInsertId() returns int|string or exception (BC break)
dg Aug 14, 2024
11f5d20
drivers: getForeignKeys() works with multi-column foreign keys
dg Sep 4, 2024
f981ccc
Explorer, Selection, Structure: change of constructor dependencies (B…
dg Aug 13, 2024
9b50bd2
Connection::getDsn() deprecated (BC break)
dg Aug 17, 2024
45c712f
auxiliary commit
dg Aug 29, 2024
b9d5ce0
merging Connection & Explorer classes into one (BC break)
dg Sep 6, 2024
33708a6
removed IStructure (BC break)
dg Sep 2, 2024
24167bc
Engine::applyLimit() returns string (BC break)
dg Sep 3, 2024
1ef0bd4
Engine::delimite() -> delimit() (BC break)
dg Sep 4, 2024
b7aeb45
Selection: uses yield for iteration
dg Sep 5, 2024
2e2aa3b
Result: uses yield for iteration
dg Sep 5, 2024
4b58125
added Explorer::createFromDsn() & createFromParameters()
dg Sep 3, 2024
a1798c0
wip php 8.4 test
dg Aug 14, 2024
1769e30
Remove importants from database panel css to allow overwrite it in cu…
website21cz Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renamed Nette\Database\Driver -> Nette\Database\Drivers\Engine (BC br…
…eak)
  • Loading branch information
dg committed Sep 4, 2024
commit 96c2e8a80edbcd5afcd5dd393b2c63bee663b15d
22 changes: 11 additions & 11 deletions src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Connection

/** @var array<callable(self, Result|DriverException): void> Occurs after query is executed */
public array $onQuery = [];
private Driver $driver;
private Drivers\Engine $engine;
private SqlPreprocessor $preprocessor;
private ?PDO $pdo = null;

Expand Down Expand Up @@ -65,9 +65,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);
}

Expand Down Expand Up @@ -98,25 +98,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());
}


Expand All @@ -133,7 +133,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);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/Database/Driver.php → src/Database/Drivers/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

declare(strict_types=1);

namespace Nette\Database;
namespace Nette\Database\Drivers;

use Nette\Database;


/**
* Supplemental PDO database driver.
* Database platform specific operations and reflection capabilities.
*/
interface Driver
interface Engine
{
public const
SupportSequence = 'sequence',
Expand All @@ -32,12 +34,12 @@ function isSupported(string $feature): bool;
/**
* 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;

/********************* SQL utilities ****************d*g**/

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/MsSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Supplemental MS SQL database driver.
*/
class MsSqlDriver implements Nette\Database\Driver
class MsSqlDriver implements Engine
{
private Nette\Database\Connection $connection;

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/OciDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/PgSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Supplemental PostgreSQL database driver.
*/
class PgSqlDriver implements Nette\Database\Driver
class PgSqlDriver implements Engine
{
private Nette\Database\Connection $connection;

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/SqliteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/SqlsrvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/Database/Explorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public function getConnection(): Connection
}


public function getDatabaseEngine(): Drivers\Engine
{
return $this->connection->getDatabaseEngine();
}


public function getStructure(): IStructure
{
return $this->structure;
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class Reflection


public function __construct(
private readonly Driver $driver,
private readonly Drivers\Engine $engine,
) {
unset($this->tables);
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Reflection/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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),
);
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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;
Expand Down Expand Up @@ -109,7 +109,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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Database/SqlPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,7 +62,7 @@ class SqlPreprocessor
public function __construct(Connection $connection)
{
$this->connection = $connection;
$this->driver = $connection->getDriver();
$this->engine = $connection->getDatabaseEngine();
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ? '' : ')');
}
Expand Down Expand Up @@ -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)));
}
}
10 changes: 5 additions & 5 deletions src/Database/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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'])) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,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) {
Expand Down
Loading