mirror of
https://github.com/dg/dibi.git
synced 2025-08-08 07:06:52 +02:00
renamed interfaces (BC break)
Dibi\Driver => Dibi\Drivers\Connection Dibi\ResultDriver => Dibi\Drivers\Result Dibi\Reflector => Dibi\Drivers\Engine
This commit is contained in:
@@ -29,7 +29,7 @@ class Connection
|
|||||||
|
|
||||||
/** @var string[] resultset formats */
|
/** @var string[] resultset formats */
|
||||||
private array $formats;
|
private array $formats;
|
||||||
private ?Driver $driver = null;
|
private ?Drivers\Connection $driver = null;
|
||||||
private ?Translator $translator = null;
|
private ?Translator $translator = null;
|
||||||
|
|
||||||
/** @var array<string, callable(object): Expression | null> */
|
/** @var array<string, callable(object): Expression | null> */
|
||||||
@@ -122,12 +122,12 @@ class Connection
|
|||||||
*/
|
*/
|
||||||
final public function connect(): void
|
final public function connect(): void
|
||||||
{
|
{
|
||||||
if ($this->config['driver'] instanceof Driver) {
|
if ($this->config['driver'] instanceof Drivers\Connection) {
|
||||||
$this->driver = $this->config['driver'];
|
$this->driver = $this->config['driver'];
|
||||||
$this->translator = new Translator($this);
|
$this->translator = new Translator($this);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} elseif (is_subclass_of($this->config['driver'], Driver::class)) {
|
} elseif (is_subclass_of($this->config['driver'], Drivers\Connection::class)) {
|
||||||
$class = $this->config['driver'];
|
$class = $this->config['driver'];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -198,7 +198,7 @@ class Connection
|
|||||||
/**
|
/**
|
||||||
* Returns the driver and connects to a database in lazy mode.
|
* Returns the driver and connects to a database in lazy mode.
|
||||||
*/
|
*/
|
||||||
final public function getDriver(): Driver
|
final public function getDriver(): Drivers\Connection
|
||||||
{
|
{
|
||||||
if (!$this->driver) {
|
if (!$this->driver) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
@@ -450,7 +450,7 @@ class Connection
|
|||||||
/**
|
/**
|
||||||
* Result set factory.
|
* Result set factory.
|
||||||
*/
|
*/
|
||||||
public function createResultSet(ResultDriver $resultDriver): Result
|
public function createResultSet(Drivers\Result $resultDriver): Result
|
||||||
{
|
{
|
||||||
return (new Result($resultDriver, $this->config['result']['normalize'] ?? true))
|
return (new Result($resultDriver, $this->config['result']['normalize'] ?? true))
|
||||||
->setFormats($this->formats);
|
->setFormats($this->formats);
|
||||||
|
97
src/Dibi/Drivers/Connection.php
Normal file
97
src/Dibi/Drivers/Connection.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
|
||||||
|
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
|
use Dibi\DriverException;
|
||||||
|
use Dibi\Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database connection driver.
|
||||||
|
*/
|
||||||
|
interface Connection
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Disconnects from a database.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
function disconnect(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal: Executes the SQL query.
|
||||||
|
* @throws DriverException
|
||||||
|
*/
|
||||||
|
function query(string $sql): ?Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||||
|
*/
|
||||||
|
function getAffectedRows(): ?int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||||
|
*/
|
||||||
|
function getInsertId(?string $sequence): ?int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begins a transaction (if supported).
|
||||||
|
* @throws DriverException
|
||||||
|
*/
|
||||||
|
function begin(?string $savepoint = null): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits statements in a transaction.
|
||||||
|
* @throws DriverException
|
||||||
|
*/
|
||||||
|
function commit(?string $savepoint = null): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rollback changes in a transaction.
|
||||||
|
* @throws DriverException
|
||||||
|
*/
|
||||||
|
function rollback(?string $savepoint = null): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the connection resource.
|
||||||
|
*/
|
||||||
|
function getResource(): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the connection reflector.
|
||||||
|
*/
|
||||||
|
function getReflector(): Engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes data for use in a SQL statement.
|
||||||
|
*/
|
||||||
|
function escapeText(string $value): string;
|
||||||
|
|
||||||
|
function escapeBinary(string $value): string;
|
||||||
|
|
||||||
|
function escapeIdentifier(string $value): string;
|
||||||
|
|
||||||
|
function escapeBool(bool $value): string;
|
||||||
|
|
||||||
|
function escapeDate(\DateTimeInterface $value): string;
|
||||||
|
|
||||||
|
function escapeDateTime(\DateTimeInterface $value): string;
|
||||||
|
|
||||||
|
function escapeDateInterval(\DateInterval $value): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes string for use in a LIKE statement.
|
||||||
|
*/
|
||||||
|
function escapeLike(string $value, int $pos): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects LIMIT/OFFSET to the SQL query.
|
||||||
|
*/
|
||||||
|
function applyLimit(string &$sql, ?int $limit, ?int $offset): void;
|
||||||
|
}
|
@@ -15,14 +15,14 @@ use Dibi;
|
|||||||
/**
|
/**
|
||||||
* The dummy driver for testing purposes.
|
* The dummy driver for testing purposes.
|
||||||
*/
|
*/
|
||||||
class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
class DummyDriver implements Connection, Result, Engine
|
||||||
{
|
{
|
||||||
public function disconnect(): void
|
public function disconnect(): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
40
src/Dibi/Drivers/Engine.php
Normal file
40
src/Dibi/Drivers/Engine.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
|
||||||
|
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Engine-specific behaviors.
|
||||||
|
*/
|
||||||
|
interface Engine
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns list of tables.
|
||||||
|
* @return array of {name [, (bool) view ]}
|
||||||
|
*/
|
||||||
|
function getTables(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns metadata for all columns in a table.
|
||||||
|
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
|
||||||
|
*/
|
||||||
|
function getColumns(string $table): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns metadata for all indexes in a table.
|
||||||
|
* @return array of {name, (array of names) columns [, (bool) unique, (bool) primary ]}
|
||||||
|
*/
|
||||||
|
function getIndexes(string $table): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns metadata for all foreign keys in a table.
|
||||||
|
*/
|
||||||
|
function getForeignKeys(string $table): array;
|
||||||
|
}
|
@@ -25,7 +25,7 @@ use function is_resource;
|
|||||||
* - buffers (int) => buffers is the number of database buffers to allocate for the server-side cache. If 0 or omitted, server chooses its own default.
|
* - buffers (int) => buffers is the number of database buffers to allocate for the server-side cache. If 0 or omitted, server chooses its own default.
|
||||||
* - resource (resource) => existing connection resource
|
* - resource (resource) => existing connection resource
|
||||||
*/
|
*/
|
||||||
class FirebirdDriver implements Dibi\Driver
|
class FirebirdDriver implements Connection
|
||||||
{
|
{
|
||||||
public const ErrorExceptionThrown = -836;
|
public const ErrorExceptionThrown = -836;
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ class FirebirdDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException|Dibi\Exception
|
* @throws Dibi\DriverException|Dibi\Exception
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$resource = $this->inTransaction
|
$resource = $this->inTransaction
|
||||||
? $this->transaction
|
? $this->transaction
|
||||||
@@ -200,7 +200,7 @@ class FirebirdDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new FirebirdReflector($this);
|
return new FirebirdReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -9,16 +9,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dibi\Drivers;
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
use Dibi;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reflector for Firebird/InterBase database.
|
* The reflector for Firebird/InterBase database.
|
||||||
*/
|
*/
|
||||||
class FirebirdReflector implements Dibi\Reflector
|
class FirebirdReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ use function is_resource;
|
|||||||
/**
|
/**
|
||||||
* The driver for Firebird/InterBase result set.
|
* The driver for Firebird/InterBase result set.
|
||||||
*/
|
*/
|
||||||
class FirebirdResult implements Dibi\ResultDriver
|
class FirebirdResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
|
@@ -16,10 +16,10 @@ use Dibi;
|
|||||||
* The reflector for MySQL databases.
|
* The reflector for MySQL databases.
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class MySqlReflector implements Dibi\Reflector
|
class MySqlReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ use const MYSQLI_REPORT_OFF, MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT, PREG_SET_OR
|
|||||||
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
|
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
|
||||||
* - resource (mysqli) => existing connection resource
|
* - resource (mysqli) => existing connection resource
|
||||||
*/
|
*/
|
||||||
class MySqliDriver implements Dibi\Driver
|
class MySqliDriver implements Connection
|
||||||
{
|
{
|
||||||
public const ErrorAccessDenied = 1045;
|
public const ErrorAccessDenied = 1045;
|
||||||
public const ErrorDuplicateEntry = 1062;
|
public const ErrorDuplicateEntry = 1062;
|
||||||
@@ -148,7 +148,7 @@ class MySqliDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$res = @$this->connection->query($sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // intentionally @
|
$res = @$this->connection->query($sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // intentionally @
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ class MySqliDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new MySqlReflector($this);
|
return new MySqlReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ use const MYSQLI_TYPE_LONG, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_TIME, MYSQLI_TYPE_TIN
|
|||||||
/**
|
/**
|
||||||
* The driver for MySQL result set.
|
* The driver for MySQL result set.
|
||||||
*/
|
*/
|
||||||
class MySqliResult implements Dibi\ResultDriver
|
class MySqliResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly \mysqli_result $resultSet,
|
private readonly \mysqli_result $resultSet,
|
||||||
|
@@ -9,13 +9,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dibi\Drivers;
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
use Dibi;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The driver for no result set.
|
* The driver for no result set.
|
||||||
*/
|
*/
|
||||||
class NoDataResult implements Dibi\ResultDriver
|
class NoDataResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly int $rows,
|
private readonly int $rows,
|
||||||
|
@@ -24,7 +24,7 @@ use function is_resource;
|
|||||||
* - resource (resource) => existing connection resource
|
* - resource (resource) => existing connection resource
|
||||||
* - microseconds (bool) => use microseconds in datetime format?
|
* - microseconds (bool) => use microseconds in datetime format?
|
||||||
*/
|
*/
|
||||||
class OdbcDriver implements Dibi\Driver
|
class OdbcDriver implements Connection
|
||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
@@ -77,7 +77,7 @@ class OdbcDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$this->affectedRows = null;
|
$this->affectedRows = null;
|
||||||
$res = @odbc_exec($this->connection, $sql); // intentionally @
|
$res = @odbc_exec($this->connection, $sql); // intentionally @
|
||||||
@@ -176,7 +176,7 @@ class OdbcDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new OdbcReflector($this);
|
return new OdbcReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,10 @@ use Dibi;
|
|||||||
/**
|
/**
|
||||||
* The reflector for ODBC connections.
|
* The reflector for ODBC connections.
|
||||||
*/
|
*/
|
||||||
class OdbcReflector implements Dibi\Reflector
|
class OdbcReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ use function is_resource;
|
|||||||
/**
|
/**
|
||||||
* The driver interacting with result set via ODBC connections.
|
* The driver interacting with result set via ODBC connections.
|
||||||
*/
|
*/
|
||||||
class OdbcResult implements Dibi\ResultDriver
|
class OdbcResult implements Result
|
||||||
{
|
{
|
||||||
private int $row = 0;
|
private int $row = 0;
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ use function in_array, is_resource;
|
|||||||
* - resource (resource) => existing connection resource
|
* - resource (resource) => existing connection resource
|
||||||
* - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect
|
* - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect
|
||||||
*/
|
*/
|
||||||
class OracleDriver implements Dibi\Driver
|
class OracleDriver implements Connection
|
||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
@@ -77,7 +77,7 @@ class OracleDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$this->affectedRows = null;
|
$this->affectedRows = null;
|
||||||
$res = oci_parse($this->connection, $sql);
|
$res = oci_parse($this->connection, $sql);
|
||||||
@@ -190,7 +190,7 @@ class OracleDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new OracleReflector($this);
|
return new OracleReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -15,10 +15,10 @@ use Dibi;
|
|||||||
/**
|
/**
|
||||||
* The reflector for Oracle database.
|
* The reflector for Oracle database.
|
||||||
*/
|
*/
|
||||||
class OracleReflector implements Dibi\Reflector
|
class OracleReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ use function is_resource;
|
|||||||
/**
|
/**
|
||||||
* The driver for Oracle result set.
|
* The driver for Oracle result set.
|
||||||
*/
|
*/
|
||||||
class OracleResult implements Dibi\ResultDriver
|
class OracleResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
|
@@ -25,7 +25,7 @@ use function sprintf;
|
|||||||
* - options (array) => driver specific options {@see PDO::__construct}
|
* - options (array) => driver specific options {@see PDO::__construct}
|
||||||
* - resource (PDO) => existing connection
|
* - resource (PDO) => existing connection
|
||||||
*/
|
*/
|
||||||
class PdoDriver implements Dibi\Driver
|
class PdoDriver implements Connection
|
||||||
{
|
{
|
||||||
private ?PDO $connection;
|
private ?PDO $connection;
|
||||||
private ?int $affectedRows;
|
private ?int $affectedRows;
|
||||||
@@ -80,7 +80,7 @@ class PdoDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$res = $this->connection->query($sql);
|
$res = $this->connection->query($sql);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
@@ -172,7 +172,7 @@ class PdoDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return match ($this->driverName) {
|
return match ($this->driverName) {
|
||||||
'mysql' => new MySqlReflector($this),
|
'mysql' => new MySqlReflector($this),
|
||||||
|
@@ -17,7 +17,7 @@ use PDO;
|
|||||||
/**
|
/**
|
||||||
* The driver for PDO result set.
|
* The driver for PDO result set.
|
||||||
*/
|
*/
|
||||||
class PdoResult implements Dibi\ResultDriver
|
class PdoResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ?\PDOStatement $resultSet,
|
private ?\PDOStatement $resultSet,
|
||||||
|
@@ -27,7 +27,7 @@ use function in_array, is_array, is_resource, strlen;
|
|||||||
* - resource (PgSql\Connection) => existing connection resource
|
* - resource (PgSql\Connection) => existing connection resource
|
||||||
* - connect_type (int) => see pg_connect()
|
* - connect_type (int) => see pg_connect()
|
||||||
*/
|
*/
|
||||||
class PostgreDriver implements Dibi\Driver
|
class PostgreDriver implements Connection
|
||||||
{
|
{
|
||||||
private PgSql\Connection $connection;
|
private PgSql\Connection $connection;
|
||||||
private ?int $affectedRows;
|
private ?int $affectedRows;
|
||||||
@@ -110,7 +110,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$this->affectedRows = null;
|
$this->affectedRows = null;
|
||||||
$res = @pg_query($this->connection, $sql); // intentionally @
|
$res = @pg_query($this->connection, $sql); // intentionally @
|
||||||
@@ -232,7 +232,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new PostgreReflector($this);
|
return new PostgreReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -9,16 +9,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dibi\Drivers;
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
use Dibi;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reflector for PostgreSQL database.
|
* The reflector for PostgreSQL database.
|
||||||
*/
|
*/
|
||||||
class PostgreReflector implements Dibi\Reflector
|
class PostgreReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dibi\Drivers;
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
use Dibi;
|
|
||||||
use Dibi\Helpers;
|
use Dibi\Helpers;
|
||||||
use PgSql;
|
use PgSql;
|
||||||
use function is_resource;
|
use function is_resource;
|
||||||
@@ -18,7 +17,7 @@ use function is_resource;
|
|||||||
/**
|
/**
|
||||||
* The driver for PostgreSQL result set.
|
* The driver for PostgreSQL result set.
|
||||||
*/
|
*/
|
||||||
class PostgreResult implements Dibi\ResultDriver
|
class PostgreResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly PgSql\Result $resultSet,
|
private readonly PgSql\Result $resultSet,
|
||||||
|
58
src/Dibi/Drivers/Result.php
Normal file
58
src/Dibi/Drivers/Result.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
|
||||||
|
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
|
use Dibi\Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database result driver.
|
||||||
|
*/
|
||||||
|
interface Result
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the number of rows in a result set.
|
||||||
|
*/
|
||||||
|
function getRowCount(): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves cursor position without fetching row.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
function seek(int $row): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||||
|
* @param bool $type true for associative array, false for numeric
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
function fetch(bool $type): ?array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the resources allocated for this result set.
|
||||||
|
*/
|
||||||
|
function free(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns metadata for all columns in a result set.
|
||||||
|
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
|
||||||
|
*/
|
||||||
|
function getResultColumns(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the result set resource.
|
||||||
|
*/
|
||||||
|
function getResultResource(): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes data from result set.
|
||||||
|
*/
|
||||||
|
function unescapeBinary(string $value): string;
|
||||||
|
}
|
@@ -23,7 +23,7 @@ use SQLite3;
|
|||||||
* - formatDateTime => how to format datetime in SQL (@see date)
|
* - formatDateTime => how to format datetime in SQL (@see date)
|
||||||
* - resource (SQLite3) => existing connection resource
|
* - resource (SQLite3) => existing connection resource
|
||||||
*/
|
*/
|
||||||
class SqliteDriver implements Dibi\Driver
|
class SqliteDriver implements Connection
|
||||||
{
|
{
|
||||||
private SQLite3 $connection;
|
private SQLite3 $connection;
|
||||||
private string $fmtDate;
|
private string $fmtDate;
|
||||||
@@ -73,7 +73,7 @@ class SqliteDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$res = @$this->connection->query($sql); // intentionally @
|
$res = @$this->connection->query($sql); // intentionally @
|
||||||
if ($code = $this->connection->lastErrorCode()) {
|
if ($code = $this->connection->lastErrorCode()) {
|
||||||
@@ -174,7 +174,7 @@ class SqliteDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new SqliteReflector($this);
|
return new SqliteReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -9,16 +9,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dibi\Drivers;
|
namespace Dibi\Drivers;
|
||||||
|
|
||||||
use Dibi;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reflector for SQLite database.
|
* The reflector for SQLite database.
|
||||||
*/
|
*/
|
||||||
class SqliteReflector implements Dibi\Reflector
|
class SqliteReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ use const SQLITE3_ASSOC, SQLITE3_BLOB, SQLITE3_FLOAT, SQLITE3_INTEGER, SQLITE3_N
|
|||||||
/**
|
/**
|
||||||
* The driver for SQLite result set.
|
* The driver for SQLite result set.
|
||||||
*/
|
*/
|
||||||
class SqliteResult implements Dibi\ResultDriver
|
class SqliteResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly \SQLite3Result $resultSet,
|
private readonly \SQLite3Result $resultSet,
|
||||||
|
@@ -26,7 +26,7 @@ use function is_resource, sprintf;
|
|||||||
* - charset => character encoding to set (default is UTF-8)
|
* - charset => character encoding to set (default is UTF-8)
|
||||||
* - resource (resource) => existing connection resource
|
* - resource (resource) => existing connection resource
|
||||||
*/
|
*/
|
||||||
class SqlsrvDriver implements Dibi\Driver
|
class SqlsrvDriver implements Connection
|
||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
@@ -84,7 +84,7 @@ class SqlsrvDriver implements Dibi\Driver
|
|||||||
* Executes the SQL query.
|
* Executes the SQL query.
|
||||||
* @throws Dibi\DriverException
|
* @throws Dibi\DriverException
|
||||||
*/
|
*/
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Result
|
||||||
{
|
{
|
||||||
$this->affectedRows = null;
|
$this->affectedRows = null;
|
||||||
$res = sqlsrv_query($this->connection, $sql);
|
$res = sqlsrv_query($this->connection, $sql);
|
||||||
@@ -171,7 +171,7 @@ class SqlsrvDriver implements Dibi\Driver
|
|||||||
/**
|
/**
|
||||||
* Returns the connection reflector.
|
* Returns the connection reflector.
|
||||||
*/
|
*/
|
||||||
public function getReflector(): Dibi\Reflector
|
public function getReflector(): Engine
|
||||||
{
|
{
|
||||||
return new SqlsrvReflector($this);
|
return new SqlsrvReflector($this);
|
||||||
}
|
}
|
||||||
|
@@ -16,10 +16,10 @@ use function sprintf;
|
|||||||
/**
|
/**
|
||||||
* The reflector for Microsoft SQL Server and SQL Azure databases.
|
* The reflector for Microsoft SQL Server and SQL Azure databases.
|
||||||
*/
|
*/
|
||||||
class SqlsrvReflector implements Dibi\Reflector
|
class SqlsrvReflector implements Engine
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Driver $driver,
|
private readonly Connection $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ use function is_resource;
|
|||||||
/**
|
/**
|
||||||
* The driver for Microsoft SQL Server and SQL Azure result set.
|
* The driver for Microsoft SQL Server and SQL Azure result set.
|
||||||
*/
|
*/
|
||||||
class SqlsrvResult implements Dibi\ResultDriver
|
class SqlsrvResult implements Result
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
|
@@ -159,7 +159,7 @@ class Helpers
|
|||||||
|
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
public static function escape(Driver $driver, $value, string $type): string
|
public static function escape(Drivers\Connection $driver, $value, string $type): string
|
||||||
{
|
{
|
||||||
$types = [
|
$types = [
|
||||||
Type::Text => 'text',
|
Type::Text => 'text',
|
||||||
|
20
src/Dibi/IDataSource.php
Normal file
20
src/Dibi/IDataSource.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
|
||||||
|
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dibi;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an interface between a dataset and data-aware components.
|
||||||
|
*/
|
||||||
|
interface IDataSource extends \Countable, \IteratorAggregate
|
||||||
|
{
|
||||||
|
//function \IteratorAggregate::getIterator();
|
||||||
|
//function \Countable::count();
|
||||||
|
}
|
@@ -28,7 +28,7 @@ use Dibi;
|
|||||||
class Column
|
class Column
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly ?Dibi\Reflector $reflector,
|
private readonly ?Dibi\Drivers\Engine $reflector,
|
||||||
private array $info,
|
private array $info,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@ class Database
|
|||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\Reflector $reflector,
|
private readonly Dibi\Drivers\Engine $reflector,
|
||||||
private ?string $name = null,
|
private ?string $name = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ class Result
|
|||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly Dibi\ResultDriver $driver,
|
private readonly Dibi\Drivers\Result $driver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ class Result
|
|||||||
{
|
{
|
||||||
if (!isset($this->columns)) {
|
if (!isset($this->columns)) {
|
||||||
$this->columns = [];
|
$this->columns = [];
|
||||||
$reflector = $this->driver instanceof Dibi\Reflector
|
$reflector = $this->driver instanceof Dibi\Drivers\Engine
|
||||||
? $this->driver
|
? $this->driver
|
||||||
: null;
|
: null;
|
||||||
foreach ($this->driver->getResultColumns() as $info) {
|
foreach ($this->driver->getResultColumns() as $info) {
|
||||||
|
@@ -26,7 +26,7 @@ use function array_values, strtolower;
|
|||||||
*/
|
*/
|
||||||
class Table
|
class Table
|
||||||
{
|
{
|
||||||
private readonly Dibi\Reflector $reflector;
|
private readonly Dibi\Drivers\Engine $reflector;
|
||||||
private string $name;
|
private string $name;
|
||||||
private bool $view;
|
private bool $view;
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ class Table
|
|||||||
private ?Index $primaryKey;
|
private ?Index $primaryKey;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Reflector $reflector, array $info)
|
public function __construct(Dibi\Drivers\Engine $reflector, array $info)
|
||||||
{
|
{
|
||||||
$this->reflector = $reflector;
|
$this->reflector = $reflector;
|
||||||
$this->name = $info['name'];
|
$this->name = $info['name'];
|
||||||
|
@@ -20,7 +20,7 @@ use const PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_NO_EMPTY;
|
|||||||
*/
|
*/
|
||||||
class Result implements IDataSource
|
class Result implements IDataSource
|
||||||
{
|
{
|
||||||
private ?ResultDriver $driver;
|
private ?Drivers\Result $driver;
|
||||||
|
|
||||||
/** Translate table */
|
/** Translate table */
|
||||||
private array $types = [];
|
private array $types = [];
|
||||||
@@ -37,7 +37,7 @@ class Result implements IDataSource
|
|||||||
private array $formats = [];
|
private array $formats = [];
|
||||||
|
|
||||||
|
|
||||||
public function __construct(ResultDriver $driver, bool $normalize = true)
|
public function __construct(Drivers\Result $driver, bool $normalize = true)
|
||||||
{
|
{
|
||||||
$this->driver = $driver;
|
$this->driver = $driver;
|
||||||
if ($normalize) {
|
if ($normalize) {
|
||||||
@@ -62,7 +62,7 @@ class Result implements IDataSource
|
|||||||
* Safe access to property $driver.
|
* Safe access to property $driver.
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
final public function getResultDriver(): ResultDriver
|
final public function getResultDriver(): Drivers\Result
|
||||||
{
|
{
|
||||||
if ($this->driver === null) {
|
if ($this->driver === null) {
|
||||||
throw new \RuntimeException('Result-set was released from memory.');
|
throw new \RuntimeException('Result-set was released from memory.');
|
||||||
|
@@ -17,8 +17,8 @@ use function array_filter, array_keys, array_splice, array_values, count, explod
|
|||||||
*/
|
*/
|
||||||
final class Translator
|
final class Translator
|
||||||
{
|
{
|
||||||
private readonly Connection $connection;
|
private Connection $connection;
|
||||||
private readonly Driver $driver;
|
private readonly Drivers\Connection $driver;
|
||||||
private int $cursor = 0;
|
private int $cursor = 0;
|
||||||
private array $args;
|
private array $args;
|
||||||
|
|
||||||
|
@@ -1,180 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
|
|
||||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Dibi;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an interface between a dataset and data-aware components.
|
|
||||||
*/
|
|
||||||
interface IDataSource extends \Countable, \IteratorAggregate
|
|
||||||
{
|
|
||||||
//function \IteratorAggregate::getIterator();
|
|
||||||
//function \Countable::count();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Driver interface.
|
|
||||||
*/
|
|
||||||
interface Driver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Disconnects from a database.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
function disconnect(): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal: Executes the SQL query.
|
|
||||||
* @throws DriverException
|
|
||||||
*/
|
|
||||||
function query(string $sql): ?ResultDriver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
|
||||||
*/
|
|
||||||
function getAffectedRows(): ?int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
|
||||||
*/
|
|
||||||
function getInsertId(?string $sequence): ?int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Begins a transaction (if supported).
|
|
||||||
* @throws DriverException
|
|
||||||
*/
|
|
||||||
function begin(?string $savepoint = null): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Commits statements in a transaction.
|
|
||||||
* @throws DriverException
|
|
||||||
*/
|
|
||||||
function commit(?string $savepoint = null): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rollback changes in a transaction.
|
|
||||||
* @throws DriverException
|
|
||||||
*/
|
|
||||||
function rollback(?string $savepoint = null): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the connection resource.
|
|
||||||
*/
|
|
||||||
function getResource(): mixed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the connection reflector.
|
|
||||||
*/
|
|
||||||
function getReflector(): Reflector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encodes data for use in a SQL statement.
|
|
||||||
*/
|
|
||||||
function escapeText(string $value): string;
|
|
||||||
|
|
||||||
function escapeBinary(string $value): string;
|
|
||||||
|
|
||||||
function escapeIdentifier(string $value): string;
|
|
||||||
|
|
||||||
function escapeBool(bool $value): string;
|
|
||||||
|
|
||||||
function escapeDate(\DateTimeInterface $value): string;
|
|
||||||
|
|
||||||
function escapeDateTime(\DateTimeInterface $value): string;
|
|
||||||
|
|
||||||
function escapeDateInterval(\DateInterval $value): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encodes string for use in a LIKE statement.
|
|
||||||
*/
|
|
||||||
function escapeLike(string $value, int $pos): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injects LIMIT/OFFSET to the SQL query.
|
|
||||||
*/
|
|
||||||
function applyLimit(string &$sql, ?int $limit, ?int $offset): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Result set driver interface.
|
|
||||||
*/
|
|
||||||
interface ResultDriver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns the number of rows in a result set.
|
|
||||||
*/
|
|
||||||
function getRowCount(): int;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Moves cursor position without fetching row.
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
function seek(int $row): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
|
||||||
* @param bool $type true for associative array, false for numeric
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
function fetch(bool $type): ?array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frees the resources allocated for this result set.
|
|
||||||
*/
|
|
||||||
function free(): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns metadata for all columns in a result set.
|
|
||||||
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
|
|
||||||
*/
|
|
||||||
function getResultColumns(): array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the result set resource.
|
|
||||||
*/
|
|
||||||
function getResultResource(): mixed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decodes data from result set.
|
|
||||||
*/
|
|
||||||
function unescapeBinary(string $value): string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflection driver.
|
|
||||||
*/
|
|
||||||
interface Reflector
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Returns list of tables.
|
|
||||||
* @return array of {name [, (bool) view ]}
|
|
||||||
*/
|
|
||||||
function getTables(): array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns metadata for all columns in a table.
|
|
||||||
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
|
|
||||||
*/
|
|
||||||
function getColumns(string $table): array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns metadata for all indexes in a table.
|
|
||||||
* @return array of {name, (array of names) columns [, (bool) unique, (bool) primary ]}
|
|
||||||
*/
|
|
||||||
function getIndexes(string $table): array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns metadata for all foreign keys in a table.
|
|
||||||
*/
|
|
||||||
function getForeignKeys(string $table): array;
|
|
||||||
}
|
|
@@ -36,7 +36,7 @@ test('config retrieval and driver instance access', function () use ($config) {
|
|||||||
|
|
||||||
Assert::null($conn->getConfig('lazy'));
|
Assert::null($conn->getConfig('lazy'));
|
||||||
Assert::same($config['driver'], $conn->getConfig('driver'));
|
Assert::same($config['driver'], $conn->getConfig('driver'));
|
||||||
Assert::type(Dibi\Driver::class, $conn->getDriver());
|
Assert::type(Dibi\Drivers\Connection::class, $conn->getDriver());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ class MockDriver extends Dibi\Drivers\SqlsrvDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function query(string $sql): ?Dibi\ResultDriver
|
public function query(string $sql): ?Dibi\Drivers\Result
|
||||||
{
|
{
|
||||||
return new MockResult;
|
return new MockResult;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user