mirror of
https://github.com/dg/dibi.git
synced 2025-08-13 17:44:11 +02:00
added PHP 7.1 scalar and return type hints
This commit is contained in:
@@ -33,7 +33,7 @@ class Panel implements Tracy\IBarPanel
|
||||
private $events = [];
|
||||
|
||||
|
||||
public function __construct($explain = TRUE, $filter = NULL)
|
||||
public function __construct(bool $explain = TRUE, int $filter = NULL)
|
||||
{
|
||||
$this->filter = $filter ? (int) $filter : Event::QUERY;
|
||||
$this->explain = $explain;
|
||||
@@ -50,9 +50,8 @@ class Panel implements Tracy\IBarPanel
|
||||
|
||||
/**
|
||||
* After event notification.
|
||||
* @return void
|
||||
*/
|
||||
public function logEvent(Event $event)
|
||||
public function logEvent(Event $event): void
|
||||
{
|
||||
if (($event->type & $this->filter) === 0) {
|
||||
return;
|
||||
@@ -63,9 +62,8 @@ class Panel implements Tracy\IBarPanel
|
||||
|
||||
/**
|
||||
* Returns blue-screen custom tab.
|
||||
* @return array|NULL
|
||||
*/
|
||||
public static function renderException($e)
|
||||
public static function renderException($e): ?array
|
||||
{
|
||||
if ($e instanceof Dibi\Exception && $e->getSql()) {
|
||||
return [
|
||||
@@ -78,9 +76,8 @@ class Panel implements Tracy\IBarPanel
|
||||
|
||||
/**
|
||||
* Returns HTML code for custom tab. (Tracy\IBarPanel)
|
||||
* @return string
|
||||
*/
|
||||
public function getTab()
|
||||
public function getTab(): string
|
||||
{
|
||||
$totalTime = 0;
|
||||
$count = count($this->events);
|
||||
@@ -96,9 +93,8 @@ class Panel implements Tracy\IBarPanel
|
||||
|
||||
/**
|
||||
* Returns HTML code for custom panel. (Tracy\IBarPanel)
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function getPanel()
|
||||
public function getPanel(): ?string
|
||||
{
|
||||
if (!$this->events) {
|
||||
return NULL;
|
||||
|
@@ -53,7 +53,7 @@ class Connection
|
||||
* @param string connection name
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($config, $name = NULL)
|
||||
public function __construct($config, string $name = NULL)
|
||||
{
|
||||
if (is_string($config)) {
|
||||
parse_str($config, $config);
|
||||
@@ -128,7 +128,6 @@ class Connection
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -139,9 +138,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
*/
|
||||
final public function connect()
|
||||
final public function connect(): void
|
||||
{
|
||||
$event = $this->onEvent ? new Event($this, Event::CONNECT) : NULL;
|
||||
try {
|
||||
@@ -158,9 +156,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
final public function disconnect()
|
||||
final public function disconnect(): void
|
||||
{
|
||||
$this->driver->disconnect();
|
||||
$this->connected = FALSE;
|
||||
@@ -169,9 +166,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Returns TRUE when connection was established.
|
||||
* @return bool
|
||||
*/
|
||||
final public function isConnected()
|
||||
final public function isConnected(): bool
|
||||
{
|
||||
return $this->connected;
|
||||
}
|
||||
@@ -180,11 +176,10 @@ class Connection
|
||||
/**
|
||||
* Returns configuration variable. If no $key is passed, returns the entire array.
|
||||
* @see self::__construct
|
||||
* @param string
|
||||
* @param mixed default value to use if key not found
|
||||
* @param mixed $default default value to use if key not found
|
||||
* @return mixed
|
||||
*/
|
||||
final public function getConfig($key = NULL, $default = NULL)
|
||||
final public function getConfig(string $key = NULL, $default = NULL)
|
||||
{
|
||||
return $key === NULL
|
||||
? $this->config
|
||||
@@ -194,9 +189,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Returns the driver and connects to a database in lazy mode.
|
||||
* @return Driver
|
||||
*/
|
||||
final public function getDriver()
|
||||
final public function getDriver(): Driver
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
return $this->driver;
|
||||
@@ -218,10 +212,9 @@ class Connection
|
||||
/**
|
||||
* Generates SQL query.
|
||||
* @param mixed one or more arguments
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
final public function translate(...$args)
|
||||
final public function translate(...$args): string
|
||||
{
|
||||
return $this->translateArgs($args);
|
||||
}
|
||||
@@ -230,9 +223,8 @@ class Connection
|
||||
/**
|
||||
* Generates and prints SQL query.
|
||||
* @param mixed one or more arguments
|
||||
* @return bool
|
||||
*/
|
||||
final public function test(...$args)
|
||||
final public function test(...$args): bool
|
||||
{
|
||||
try {
|
||||
Helpers::dump($this->translateArgs($args));
|
||||
@@ -252,10 +244,9 @@ class Connection
|
||||
/**
|
||||
* Generates (translates) and returns SQL query as DataSource.
|
||||
* @param mixed one or more arguments
|
||||
* @return DataSource
|
||||
* @throws Exception
|
||||
*/
|
||||
final public function dataSource(...$args)
|
||||
final public function dataSource(...$args): DataSource
|
||||
{
|
||||
return new DataSource($this->translateArgs($args), $this);
|
||||
}
|
||||
@@ -263,10 +254,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Generates SQL query.
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
protected function translateArgs($args)
|
||||
protected function translateArgs(array $args): string
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
if (!$this->translator) {
|
||||
@@ -283,7 +272,7 @@ class Connection
|
||||
* @return Result|int result set or number of affected rows
|
||||
* @throws Exception
|
||||
*/
|
||||
final public function nativeQuery($sql)
|
||||
final public function nativeQuery(string $sql)
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
|
||||
@@ -313,7 +302,7 @@ class Connection
|
||||
* @return int number of rows
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): int
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$rows = $this->driver->getAffectedRows();
|
||||
@@ -329,7 +318,7 @@ class Connection
|
||||
* @return int number of rows
|
||||
* @throws Exception
|
||||
*/
|
||||
public function affectedRows()
|
||||
public function affectedRows(): int
|
||||
{
|
||||
return $this->getAffectedRows();
|
||||
}
|
||||
@@ -338,10 +327,9 @@ class Connection
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @param string optional sequence name
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getInsertId($sequence = NULL)
|
||||
public function getInsertId(string $sequence = NULL): int
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$id = $this->driver->getInsertId($sequence);
|
||||
@@ -355,10 +343,9 @@ class Connection
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
||||
* @param string optional sequence name
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function insertId($sequence = NULL)
|
||||
public function insertId(string $sequence = NULL): int
|
||||
{
|
||||
return $this->getInsertId($sequence);
|
||||
}
|
||||
@@ -367,9 +354,8 @@ class Connection
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$event = $this->onEvent ? new Event($this, Event::BEGIN, $savepoint) : NULL;
|
||||
@@ -387,9 +373,8 @@ class Connection
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$event = $this->onEvent ? new Event($this, Event::COMMIT, $savepoint) : NULL;
|
||||
@@ -407,9 +392,8 @@ class Connection
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
$event = $this->onEvent ? new Event($this, Event::ROLLBACK, $savepoint) : NULL;
|
||||
@@ -426,10 +410,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Result set factory.
|
||||
* @param ResultDriver
|
||||
* @return Result
|
||||
*/
|
||||
public function createResultSet(ResultDriver $resultDriver)
|
||||
public function createResultSet(ResultDriver $resultDriver): Result
|
||||
{
|
||||
$res = new Result($resultDriver);
|
||||
return $res->setFormat(Type::DATE, $this->config['result']['formatDate'])
|
||||
@@ -440,10 +422,7 @@ class Connection
|
||||
/********************* fluent SQL builders ****************d*g**/
|
||||
|
||||
|
||||
/**
|
||||
* @return Fluent
|
||||
*/
|
||||
public function command()
|
||||
public function command(): Fluent
|
||||
{
|
||||
return new Fluent($this);
|
||||
}
|
||||
@@ -451,20 +430,14 @@ class Connection
|
||||
|
||||
/**
|
||||
* @param mixed column name
|
||||
* @return Fluent
|
||||
*/
|
||||
public function select(...$args)
|
||||
public function select(...$args): Fluent
|
||||
{
|
||||
return $this->command()->select(...$args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @param array
|
||||
* @return Fluent
|
||||
*/
|
||||
public function update($table, $args)
|
||||
public function update(string $table, array $args): Fluent
|
||||
{
|
||||
if (!(is_array($args) || $args instanceof Traversable)) {
|
||||
throw new \InvalidArgumentException('Arguments must be array or Traversable.');
|
||||
@@ -473,12 +446,7 @@ class Connection
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @param array
|
||||
* @return Fluent
|
||||
*/
|
||||
public function insert($table, $args)
|
||||
public function insert(string $table, array $args): Fluent
|
||||
{
|
||||
if ($args instanceof Traversable) {
|
||||
$args = iterator_to_array($args);
|
||||
@@ -490,11 +458,7 @@ class Connection
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @return Fluent
|
||||
*/
|
||||
public function delete($table)
|
||||
public function delete(string $table): Fluent
|
||||
{
|
||||
return $this->command()->delete()->from('%n', $table);
|
||||
}
|
||||
@@ -505,9 +469,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Returns substitution hashmap.
|
||||
* @return HashMap
|
||||
*/
|
||||
public function getSubstitutes()
|
||||
public function getSubstitutes(): HashMap
|
||||
{
|
||||
return $this->substitutes;
|
||||
}
|
||||
@@ -515,9 +478,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Provides substitution.
|
||||
* @return string
|
||||
*/
|
||||
public function substitute($value)
|
||||
public function substitute(string $value): string
|
||||
{
|
||||
return strpos($value, ':') === FALSE
|
||||
? $value
|
||||
@@ -546,7 +508,7 @@ class Connection
|
||||
* @return Row[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchAll(...$args)
|
||||
public function fetchAll(...$args): array
|
||||
{
|
||||
return $this->query($args)->fetchAll();
|
||||
}
|
||||
@@ -567,19 +529,15 @@ class Connection
|
||||
/**
|
||||
* Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
|
||||
* @param mixed one or more arguments
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchPairs(...$args)
|
||||
public function fetchPairs(...$args): array
|
||||
{
|
||||
return $this->query($args)->fetchPairs();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Literal
|
||||
*/
|
||||
public static function literal($value)
|
||||
public static function literal($value): Literal
|
||||
{
|
||||
return new Literal($value);
|
||||
}
|
||||
@@ -594,7 +552,7 @@ class Connection
|
||||
* @param callable function (int $count, ?float $percent): void
|
||||
* @return int count of sql commands
|
||||
*/
|
||||
public function loadFile($file, callable $onProgress = NULL)
|
||||
public function loadFile(string $file, callable $onProgress = NULL): int
|
||||
{
|
||||
return Helpers::loadFromFile($this, $file, $onProgress);
|
||||
}
|
||||
@@ -602,9 +560,8 @@ class Connection
|
||||
|
||||
/**
|
||||
* Gets a information about the current database.
|
||||
* @return Reflection\Database
|
||||
*/
|
||||
public function getDatabaseInfo()
|
||||
public function getDatabaseInfo(): Reflection\Database
|
||||
{
|
||||
$this->connected || $this->connect();
|
||||
return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? NULL);
|
||||
|
@@ -49,9 +49,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* @param string SQL command or table or view name, as data source
|
||||
* @param Connection connection
|
||||
*/
|
||||
public function __construct($sql, Connection $connection)
|
||||
public function __construct(string $sql, Connection $connection)
|
||||
{
|
||||
if (strpbrk($sql, " \t\r\n") === FALSE) {
|
||||
$this->sql = $connection->getDriver()->escapeIdentifier($sql); // table name
|
||||
@@ -66,9 +65,8 @@ class DataSource implements IDataSource
|
||||
* Selects columns to query.
|
||||
* @param string|array column name or array of column names
|
||||
* @param string column alias
|
||||
* @return self
|
||||
*/
|
||||
public function select($col, $as = NULL)
|
||||
public function select($col, string $as = NULL): self
|
||||
{
|
||||
if (is_array($col)) {
|
||||
$this->cols = $col;
|
||||
@@ -83,9 +81,8 @@ class DataSource implements IDataSource
|
||||
/**
|
||||
* Adds conditions to query.
|
||||
* @param mixed conditions
|
||||
* @return self
|
||||
*/
|
||||
public function where($cond)
|
||||
public function where($cond): self
|
||||
{
|
||||
if (is_array($cond)) {
|
||||
// TODO: not consistent with select and orderBy
|
||||
@@ -102,9 +99,8 @@ class DataSource implements IDataSource
|
||||
* Selects columns to order by.
|
||||
* @param string|array column name or array of column names
|
||||
* @param string sorting direction
|
||||
* @return self
|
||||
*/
|
||||
public function orderBy($row, $sorting = 'ASC')
|
||||
public function orderBy($row, string $sorting = 'ASC'): self
|
||||
{
|
||||
if (is_array($row)) {
|
||||
$this->sorting = $row;
|
||||
@@ -118,11 +114,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Limits number of rows.
|
||||
* @param int|NULL limit
|
||||
* @param int offset
|
||||
* @return self
|
||||
*/
|
||||
public function applyLimit($limit, $offset = NULL)
|
||||
public function applyLimit(int $limit, int $offset = NULL): self
|
||||
{
|
||||
$this->limit = $limit;
|
||||
$this->offset = $offset;
|
||||
@@ -133,9 +126,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns the dibi connection.
|
||||
* @return Connection
|
||||
*/
|
||||
final public function getConnection()
|
||||
final public function getConnection(): Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
@@ -146,9 +138,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns (and queries) Result.
|
||||
* @return Result
|
||||
*/
|
||||
public function getResult()
|
||||
public function getResult(): Result
|
||||
{
|
||||
if ($this->result === NULL) {
|
||||
$this->result = $this->connection->nativeQuery($this->__toString());
|
||||
@@ -157,10 +148,7 @@ class DataSource implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ResultIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
public function getIterator(): ResultIterator
|
||||
{
|
||||
return $this->getResult()->getIterator();
|
||||
}
|
||||
@@ -188,9 +176,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Fetches all records from table.
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAll()
|
||||
public function fetchAll(): array
|
||||
{
|
||||
return $this->getResult()->fetchAll();
|
||||
}
|
||||
@@ -199,9 +186,8 @@ class DataSource implements IDataSource
|
||||
/**
|
||||
* Fetches all records from table and returns associative tree.
|
||||
* @param string associative descriptor
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAssoc($assoc)
|
||||
public function fetchAssoc(string $assoc): array
|
||||
{
|
||||
return $this->getResult()->fetchAssoc($assoc);
|
||||
}
|
||||
@@ -210,10 +196,8 @@ class DataSource implements IDataSource
|
||||
/**
|
||||
* Fetches all records from table like $key => $value pairs.
|
||||
* @param string associative key
|
||||
* @param string value
|
||||
* @return array
|
||||
*/
|
||||
public function fetchPairs($key = NULL, $value = NULL)
|
||||
public function fetchPairs(string $key = NULL, string $value = NULL): array
|
||||
{
|
||||
return $this->getResult()->fetchPairs($key, $value);
|
||||
}
|
||||
@@ -221,9 +205,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Discards the internal cache.
|
||||
* @return void
|
||||
*/
|
||||
public function release()
|
||||
public function release(): void
|
||||
{
|
||||
$this->result = $this->count = $this->totalCount = NULL;
|
||||
}
|
||||
@@ -234,9 +217,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns this data source wrapped in Fluent object.
|
||||
* @return Fluent
|
||||
*/
|
||||
public function toFluent()
|
||||
public function toFluent(): Fluent
|
||||
{
|
||||
return $this->connection->select('*')->from('(%SQL) t', $this->__toString());
|
||||
}
|
||||
@@ -244,9 +226,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns this data source wrapped in DataSource object.
|
||||
* @return DataSource
|
||||
*/
|
||||
public function toDataSource()
|
||||
public function toDataSource(): DataSource
|
||||
{
|
||||
return new self($this->__toString(), $this->connection);
|
||||
}
|
||||
@@ -254,9 +235,8 @@ class DataSource implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns SQL query.
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
try {
|
||||
return $this->connection->translate('
|
||||
@@ -277,9 +257,8 @@ FROM %SQL', $this->sql, '
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a given data source.
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
if ($this->count === NULL) {
|
||||
$this->count = $this->conds || $this->offset || $this->limit
|
||||
@@ -294,9 +273,8 @@ FROM %SQL', $this->sql, '
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a given data source.
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCount()
|
||||
public function getTotalCount(): int
|
||||
{
|
||||
if ($this->totalCount === NULL) {
|
||||
$this->totalCount = (int) $this->connection->nativeQuery(
|
||||
|
@@ -31,7 +31,7 @@ class DateTime extends \DateTime
|
||||
}
|
||||
|
||||
|
||||
public function modifyClone($modify = '')
|
||||
public function modifyClone(string $modify = '')
|
||||
{
|
||||
$dolly = clone($this);
|
||||
return $modify ? $dolly->modify($modify) : $dolly;
|
||||
|
@@ -58,10 +58,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
Helpers::alias($config, 'database', 'db');
|
||||
|
||||
@@ -93,9 +92,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@ibase_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -104,10 +102,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException|Dibi\Exception
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$resource = $this->inTransaction ? $this->transaction : $this->connection;
|
||||
$res = ibase_query($resource, $sql);
|
||||
@@ -130,9 +127,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return Helpers::false2Null(ibase_affected_rows($this->connection));
|
||||
}
|
||||
@@ -140,10 +136,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @param string generator name
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
return Helpers::false2Null(ibase_gen_id($sequence, 0, $this->connection));
|
||||
}
|
||||
@@ -152,10 +146,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
if ($savepoint !== NULL) {
|
||||
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
||||
@@ -168,10 +161,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
if ($savepoint !== NULL) {
|
||||
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
||||
@@ -188,10 +180,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
if ($savepoint !== NULL) {
|
||||
throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.');
|
||||
@@ -207,9 +198,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Is in transaction?
|
||||
* @return bool
|
||||
*/
|
||||
public function inTransaction()
|
||||
public function inTransaction(): bool
|
||||
{
|
||||
return $this->inTransaction;
|
||||
}
|
||||
@@ -227,9 +217,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
@@ -238,9 +227,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver($resource)
|
||||
public function createResultDriver($resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -253,40 +241,26 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
return '"' . str_replace('"', '""', $value). '"';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -294,9 +268,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -307,9 +280,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -320,11 +292,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
@@ -332,10 +301,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -343,12 +310,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit > 0 || $offset > 0) {
|
||||
// http://www.firebirdsql.org/refdocs/langrefupd20-select.html
|
||||
@@ -362,7 +325,6 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -372,9 +334,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Firebird/Interbase do not support returning number of rows in result set.');
|
||||
}
|
||||
@@ -383,9 +344,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
$result = $assoc ? @ibase_fetch_assoc($this->resultSet, IBASE_TEXT) : @ibase_fetch_row($this->resultSet, IBASE_TEXT); // intentionally @
|
||||
|
||||
@@ -405,11 +365,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Firebird/Interbase do not support seek in result set.');
|
||||
}
|
||||
@@ -417,9 +375,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
ibase_free_result($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -439,9 +396,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = ibase_num_fields($this->resultSet);
|
||||
$columns = [];
|
||||
@@ -463,9 +419,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$RELATION_NAME),
|
||||
@@ -486,10 +441,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$table = strtoupper($table);
|
||||
$res = $this->query("
|
||||
@@ -541,10 +494,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table (the constraints are included).
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
$table = strtoupper($table);
|
||||
$res = $this->query("
|
||||
@@ -575,10 +526,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
$table = strtoupper($table);
|
||||
$res = $this->query("
|
||||
@@ -605,10 +554,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of indices in given table (the constraints are not listed).
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndices($table)
|
||||
public function getIndices(string $table): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$INDEX_NAME)
|
||||
@@ -627,10 +574,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of constraints in given table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getConstraints($table)
|
||||
public function getConstraints(string $table): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$INDEX_NAME)
|
||||
@@ -652,11 +597,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Returns metadata for all triggers in a table or database.
|
||||
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
|
||||
* @param string
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getTriggersMeta($table = NULL)
|
||||
public function getTriggersMeta(string $table = NULL): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$TRIGGER_NAME) AS TRIGGER_NAME,
|
||||
@@ -701,10 +643,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Returns list of triggers for given table.
|
||||
* (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table)
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getTriggers($table = NULL)
|
||||
public function getTriggers(string $table = NULL): array
|
||||
{
|
||||
$q = "SELECT TRIM(RDB\$TRIGGER_NAME)
|
||||
FROM RDB\$TRIGGERS
|
||||
@@ -723,9 +663,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Returns metadata from stored procedures and their input and output parameters.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getProceduresMeta()
|
||||
public function getProceduresMeta(): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT
|
||||
@@ -775,9 +714,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of stored procedures.
|
||||
* @return array
|
||||
*/
|
||||
public function getProcedures()
|
||||
public function getProcedures(): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$PROCEDURE_NAME)
|
||||
@@ -793,9 +731,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of generators.
|
||||
* @return array
|
||||
*/
|
||||
public function getGenerators()
|
||||
public function getGenerators(): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$GENERATOR_NAME)
|
||||
@@ -812,9 +749,8 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of user defined functions (UDF).
|
||||
* @return array
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
$res = $this->query("
|
||||
SELECT TRIM(RDB\$FUNCTION_NAME)
|
||||
|
@@ -49,10 +49,9 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
if (isset($config['resource'])) {
|
||||
$this->connection = $config['resource'];
|
||||
@@ -74,9 +73,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@mssql_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -85,10 +83,9 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$res = @mssql_query($sql, $this->connection); // intentionally @
|
||||
|
||||
@@ -104,9 +101,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return Dibi\Helpers::false2Null(mssql_rows_affected($this->connection));
|
||||
}
|
||||
@@ -114,9 +110,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
$res = mssql_query('SELECT @@IDENTITY', $this->connection);
|
||||
if (is_resource($res)) {
|
||||
@@ -130,10 +125,9 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query('BEGIN TRANSACTION');
|
||||
}
|
||||
@@ -142,10 +136,9 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query('COMMIT');
|
||||
}
|
||||
@@ -154,10 +147,9 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query('ROLLBACK');
|
||||
}
|
||||
@@ -175,9 +167,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return new MsSqlReflector($this);
|
||||
}
|
||||
@@ -186,9 +177,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver($resource)
|
||||
public function createResultDriver($resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -201,41 +191,27 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
// @see https://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||
return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -243,9 +219,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -256,9 +231,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -269,11 +243,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||
@@ -282,10 +253,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -293,12 +262,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($offset) {
|
||||
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
||||
@@ -317,7 +282,6 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -327,9 +291,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
return mssql_num_rows($this->resultSet);
|
||||
}
|
||||
@@ -338,9 +301,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
return Dibi\Helpers::false2Null(mssql_fetch_array($this->resultSet, $assoc ? MSSQL_ASSOC : MSSQL_NUM));
|
||||
}
|
||||
@@ -351,7 +313,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
return mssql_data_seek($this->resultSet, $row);
|
||||
}
|
||||
@@ -359,9 +321,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
mssql_free_result($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -370,9 +331,8 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = mssql_num_fields($this->resultSet);
|
||||
$columns = [];
|
||||
|
@@ -30,9 +30,8 @@ class MsSqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = $this->driver->query('
|
||||
SELECT TABLE_NAME, TABLE_TYPE
|
||||
@@ -51,10 +50,8 @@ class MsSqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns count of rows in a table
|
||||
* @param string
|
||||
* @return int
|
||||
*/
|
||||
public function getTableCount($table, $fallback = TRUE)
|
||||
public function getTableCount(string $table, bool $fallback = TRUE): int
|
||||
{
|
||||
if (empty($table)) {
|
||||
return NULL;
|
||||
@@ -83,10 +80,8 @@ class MsSqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("
|
||||
SELECT * FROM
|
||||
@@ -133,10 +128,8 @@ class MsSqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
$res = $this->driver->query(
|
||||
"SELECT ind.name index_name, ind.index_id, ic.index_column_id,
|
||||
@@ -174,10 +167,8 @@ class MsSqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("
|
||||
SELECT f.name AS foreign_key,
|
||||
|
@@ -30,9 +30,8 @@ class MySqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = $this->driver->query('SHOW FULL TABLES');
|
||||
$tables = [];
|
||||
@@ -48,10 +47,8 @@ class MySqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}");
|
||||
$columns = [];
|
||||
@@ -75,10 +72,8 @@ class MySqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}");
|
||||
$indexes = [];
|
||||
@@ -94,11 +89,9 @@ class MySqlReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
* @throws Dibi\NotSupportedException
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
$data = $this->driver->query("SELECT `ENGINE` FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = {$this->driver->escapeText($table)}")->fetch(TRUE);
|
||||
if ($data['ENGINE'] !== 'InnoDB') {
|
||||
|
@@ -63,10 +63,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
if (isset($config['resource'])) {
|
||||
@@ -134,9 +133,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@mysqli_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -145,10 +143,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$res = @mysqli_query($this->connection, $sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // intentionally @
|
||||
|
||||
@@ -162,10 +159,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Dibi\DriverException
|
||||
*/
|
||||
public static function createException($message, $code, $sql)
|
||||
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
||||
{
|
||||
if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) {
|
||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||
@@ -184,9 +178,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Retrieves information about the most recently executed query.
|
||||
* @return array
|
||||
*/
|
||||
public function getInfo()
|
||||
public function getInfo(): array
|
||||
{
|
||||
$res = [];
|
||||
preg_match_all('#(.+?): +(\d+) *#', mysqli_info($this->connection), $matches, PREG_SET_ORDER);
|
||||
@@ -203,9 +196,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return mysqli_affected_rows($this->connection) === -1 ? NULL : mysqli_affected_rows($this->connection);
|
||||
}
|
||||
@@ -213,9 +205,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
return mysqli_insert_id($this->connection);
|
||||
}
|
||||
@@ -224,10 +215,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
|
||||
}
|
||||
@@ -236,10 +226,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
||||
}
|
||||
@@ -248,10 +237,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
||||
}
|
||||
@@ -259,9 +247,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection resource.
|
||||
* @return \mysqli
|
||||
*/
|
||||
public function getResource()
|
||||
public function getResource(): \mysqli
|
||||
{
|
||||
return @$this->connection->thread_id ? $this->connection : NULL;
|
||||
}
|
||||
@@ -269,9 +256,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return new MySqlReflector($this);
|
||||
}
|
||||
@@ -279,9 +265,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver(\mysqli_result $resource)
|
||||
public function createResultDriver(\mysqli_result $resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -294,40 +279,26 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . mysqli_real_escape_string($this->connection, $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "_binary'" . mysqli_real_escape_string($this->connection, $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
return '`' . str_replace('`', '``', $value) . '`';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -335,9 +306,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -348,9 +318,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -361,11 +330,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_");
|
||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||
@@ -374,10 +340,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -385,12 +349,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit < 0 || $offset < 0) {
|
||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||
@@ -408,7 +368,6 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -418,9 +377,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
if (!$this->buffered) {
|
||||
throw new Dibi\NotSupportedException('Row count is not available for unbuffered queries.');
|
||||
@@ -432,9 +390,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
return mysqli_fetch_array($this->resultSet, $assoc ? MYSQLI_ASSOC : MYSQLI_NUM);
|
||||
}
|
||||
@@ -442,11 +399,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
if (!$this->buffered) {
|
||||
throw new Dibi\NotSupportedException('Cannot seek an unbuffered result set.');
|
||||
@@ -457,9 +412,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
mysqli_free_result($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -468,9 +422,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
static $types;
|
||||
if ($types === NULL) {
|
||||
@@ -503,9 +456,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the result set resource.
|
||||
* @return \mysqli_result|NULL
|
||||
*/
|
||||
public function getResultResource()
|
||||
public function getResultResource(): ?\mysqli_result
|
||||
{
|
||||
$this->autoFree = FALSE;
|
||||
return $this->resultSet;
|
||||
|
@@ -54,10 +54,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
if (isset($config['resource'])) {
|
||||
$this->connection = $config['resource'];
|
||||
@@ -84,9 +83,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@odbc_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -95,10 +93,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$this->affectedRows = NULL;
|
||||
$res = @odbc_exec($this->connection, $sql); // intentionally @
|
||||
@@ -116,9 +113,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return $this->affectedRows;
|
||||
}
|
||||
@@ -126,9 +122,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
throw new Dibi\NotSupportedException('ODBC does not support autoincrementing.');
|
||||
}
|
||||
@@ -137,10 +132,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
if (!odbc_autocommit($this->connection, FALSE)) {
|
||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
||||
@@ -151,10 +145,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
if (!odbc_commit($this->connection)) {
|
||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
||||
@@ -166,10 +159,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
if (!odbc_rollback($this->connection)) {
|
||||
throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
|
||||
@@ -180,9 +172,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Is in transaction?
|
||||
* @return bool
|
||||
*/
|
||||
public function inTransaction()
|
||||
public function inTransaction(): bool
|
||||
{
|
||||
return !odbc_autocommit($this->connection);
|
||||
}
|
||||
@@ -200,9 +191,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
@@ -211,9 +201,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver($resource)
|
||||
public function createResultDriver($resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -226,40 +215,26 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -267,9 +242,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -280,9 +254,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -293,11 +266,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||
@@ -306,10 +276,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -317,12 +285,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($offset) {
|
||||
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
||||
@@ -341,7 +305,6 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -351,9 +314,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
// will return -1 with many drivers :-(
|
||||
return odbc_num_rows($this->resultSet);
|
||||
@@ -363,9 +325,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
if ($assoc) {
|
||||
return Dibi\Helpers::false2Null(odbc_fetch_array($this->resultSet, ++$this->row));
|
||||
@@ -386,10 +347,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
$this->row = $row;
|
||||
return TRUE;
|
||||
@@ -398,9 +357,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
odbc_free_result($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -409,9 +367,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = odbc_num_fields($this->resultSet);
|
||||
$columns = [];
|
||||
@@ -443,9 +400,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = odbc_tables($this->connection);
|
||||
$tables = [];
|
||||
@@ -464,10 +420,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$res = odbc_columns($this->connection);
|
||||
$columns = [];
|
||||
@@ -490,10 +444,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
@@ -501,10 +453,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
|
@@ -60,10 +60,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
$foo = &$config['charset'];
|
||||
|
||||
@@ -93,9 +92,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@oci_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -104,10 +102,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$this->affectedRows = NULL;
|
||||
$res = oci_parse($this->connection, $sql);
|
||||
@@ -129,10 +126,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Dibi\DriverException
|
||||
*/
|
||||
public static function createException($message, $code, $sql)
|
||||
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
||||
{
|
||||
if (in_array($code, [1, 2299, 38911], TRUE)) {
|
||||
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
||||
@@ -151,9 +145,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return $this->affectedRows;
|
||||
}
|
||||
@@ -161,9 +154,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
$row = $this->query("SELECT $sequence.CURRVAL AS ID FROM DUAL")->fetch(TRUE);
|
||||
return isset($row['ID']) ? (int) $row['ID'] : NULL;
|
||||
@@ -173,9 +165,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
$this->autocommit = FALSE;
|
||||
}
|
||||
@@ -184,10 +175,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
if (!oci_commit($this->connection)) {
|
||||
$err = oci_error($this->connection);
|
||||
@@ -200,10 +190,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
if (!oci_rollback($this->connection)) {
|
||||
$err = oci_error($this->connection);
|
||||
@@ -225,9 +214,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
@@ -236,9 +224,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver($resource)
|
||||
public function createResultDriver($resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -251,41 +238,27 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'"; // TODO: not tested
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'"; // TODO: not tested
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
// @see http://download.oracle.com/docs/cd/B10500_01/server.920/a96540/sql_elements9a.htm
|
||||
return '"' . str_replace('"', '""', $value) . '"';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -293,9 +266,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -308,9 +280,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -323,11 +294,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\\%_");
|
||||
$value = str_replace("'", "''", $value);
|
||||
@@ -337,10 +305,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -348,12 +314,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit < 0 || $offset < 0) {
|
||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||
@@ -375,7 +337,6 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -385,9 +346,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Row count is not available for unbuffered queries.');
|
||||
}
|
||||
@@ -396,9 +356,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
return Dibi\Helpers::false2Null(oci_fetch_array($this->resultSet, ($assoc ? OCI_ASSOC : OCI_NUM) | OCI_RETURN_NULLS));
|
||||
}
|
||||
@@ -406,10 +365,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
@@ -417,9 +374,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
oci_free_statement($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -428,9 +384,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = oci_num_fields($this->resultSet);
|
||||
$columns = [];
|
||||
@@ -463,9 +418,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = $this->query('SELECT * FROM cat');
|
||||
$tables = [];
|
||||
@@ -483,10 +437,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$res = $this->query('SELECT * FROM "ALL_TAB_COLUMNS" WHERE "TABLE_NAME" = ' . $this->escapeText($table));
|
||||
$columns = [];
|
||||
@@ -507,10 +459,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
@@ -518,10 +468,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
|
@@ -57,10 +57,9 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
$foo = &$config['dsn'];
|
||||
$foo = &$config['options'];
|
||||
@@ -88,9 +87,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
$this->connection = NULL;
|
||||
}
|
||||
@@ -99,10 +97,9 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
// must detect if SQL returns result set or num of affected rows
|
||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
||||
@@ -144,9 +141,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return $this->affectedRows;
|
||||
}
|
||||
@@ -154,9 +150,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
return Helpers::false2Null($this->connection->lastInsertId());
|
||||
}
|
||||
@@ -165,10 +160,9 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
if (!$this->connection->beginTransaction()) {
|
||||
$err = $this->connection->errorInfo();
|
||||
@@ -180,10 +174,9 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
if (!$this->connection->commit()) {
|
||||
$err = $this->connection->errorInfo();
|
||||
@@ -195,10 +188,9 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
if (!$this->connection->rollBack()) {
|
||||
$err = $this->connection->errorInfo();
|
||||
@@ -209,9 +201,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection resource.
|
||||
* @return PDO
|
||||
*/
|
||||
public function getResource()
|
||||
public function getResource(): PDO
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
@@ -219,9 +210,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
switch ($this->driverName) {
|
||||
case 'mysql':
|
||||
@@ -238,10 +228,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param \PDOStatement
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver(\PDOStatement $resource)
|
||||
public function createResultDriver(\PDOStatement $resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -254,10 +242,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
if ($this->driverName === 'odbc') {
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
@@ -267,11 +253,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
if ($this->driverName === 'odbc') {
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
@@ -281,11 +263,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
switch ($this->driverName) {
|
||||
case 'mysql':
|
||||
@@ -312,11 +290,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
if ($this->driverName === 'pgsql') {
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
@@ -328,9 +302,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -341,9 +314,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -354,11 +326,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
switch ($this->driverName) {
|
||||
case 'mysql':
|
||||
@@ -395,10 +364,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -406,12 +373,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit < 0 || $offset < 0) {
|
||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||
@@ -489,9 +452,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
return $this->resultSet->rowCount();
|
||||
}
|
||||
@@ -500,9 +462,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
return Helpers::false2Null($this->resultSet->fetch($assoc ? PDO::FETCH_ASSOC : PDO::FETCH_NUM));
|
||||
}
|
||||
@@ -510,10 +471,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Cannot seek an unbuffered result set.');
|
||||
}
|
||||
@@ -521,9 +480,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
$this->resultSet = NULL;
|
||||
}
|
||||
@@ -531,10 +489,9 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = $this->resultSet->columnCount();
|
||||
$columns = [];
|
||||
@@ -563,9 +520,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the result set resource.
|
||||
* @return \PDOStatement|NULL
|
||||
*/
|
||||
public function getResultResource()
|
||||
public function getResultResource(): ?\PDOStatement
|
||||
{
|
||||
return $this->resultSet;
|
||||
}
|
||||
|
@@ -53,10 +53,9 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
$error = NULL;
|
||||
if (isset($config['resource'])) {
|
||||
@@ -108,9 +107,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@pg_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -118,9 +116,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Pings database.
|
||||
* @return bool
|
||||
*/
|
||||
public function ping()
|
||||
public function ping(): bool
|
||||
{
|
||||
return pg_ping($this->connection);
|
||||
}
|
||||
@@ -129,10 +126,9 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$this->affectedRows = NULL;
|
||||
$res = @pg_query($this->connection, $sql); // intentionally @
|
||||
@@ -150,10 +146,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Dibi\DriverException
|
||||
*/
|
||||
public static function createException($message, $code = NULL, $sql = NULL)
|
||||
public static function createException(string $message, $code = NULL, string $sql = NULL): Dibi\DriverException
|
||||
{
|
||||
if ($code === NULL && preg_match('#^ERROR:\s+(\S+):\s*#', $message, $m)) {
|
||||
$code = $m[1];
|
||||
@@ -180,9 +173,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return $this->affectedRows;
|
||||
}
|
||||
@@ -190,9 +182,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
if ($sequence === NULL) {
|
||||
// PostgreSQL 8.1 is needed
|
||||
@@ -213,10 +204,9 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION');
|
||||
}
|
||||
@@ -225,10 +215,9 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
||||
}
|
||||
@@ -237,10 +226,9 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
||||
}
|
||||
@@ -248,9 +236,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Is in transaction?
|
||||
* @return bool
|
||||
*/
|
||||
public function inTransaction()
|
||||
public function inTransaction(): bool
|
||||
{
|
||||
return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], TRUE);
|
||||
}
|
||||
@@ -268,9 +255,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
@@ -279,9 +265,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver($resource)
|
||||
public function createResultDriver($resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -294,10 +279,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
if (!is_resource($this->connection)) {
|
||||
throw new Dibi\Exception('Lost connection to server.');
|
||||
@@ -306,11 +289,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
if (!is_resource($this->connection)) {
|
||||
throw new Dibi\Exception('Lost connection to server.');
|
||||
@@ -319,22 +298,14 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
// @see http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
|
||||
return '"' . str_replace('"', '""', $value) . '"';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
@@ -342,9 +313,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -355,9 +325,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -368,11 +337,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$bs = pg_escape_string($this->connection, '\\'); // standard_conforming_strings = on/off
|
||||
$value = pg_escape_string($this->connection, $value);
|
||||
@@ -383,10 +349,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return pg_unescape_bytea($value);
|
||||
}
|
||||
@@ -394,12 +358,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit < 0 || $offset < 0) {
|
||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||
@@ -418,7 +378,6 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -428,9 +387,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
return pg_num_rows($this->resultSet);
|
||||
}
|
||||
@@ -439,9 +397,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
return Helpers::false2Null(pg_fetch_array($this->resultSet, NULL, $assoc ? PGSQL_ASSOC : PGSQL_NUM));
|
||||
}
|
||||
@@ -449,10 +406,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
return pg_result_seek($this->resultSet, $row);
|
||||
}
|
||||
@@ -460,9 +415,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
pg_free_result($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -471,9 +425,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = pg_num_fields($this->resultSet);
|
||||
$columns = [];
|
||||
@@ -506,9 +459,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$version = pg_parameter_status($this->getResource(), 'server_version');
|
||||
if ($version < 7.4) {
|
||||
@@ -546,10 +498,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$_table = $this->escapeText($this->escapeIdentifier($table));
|
||||
$res = $this->query("
|
||||
@@ -613,10 +563,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
$_table = $this->escapeText($this->escapeIdentifier($table));
|
||||
$res = $this->query("
|
||||
@@ -661,10 +609,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
$_table = $this->escapeText($this->escapeIdentifier($table));
|
||||
|
||||
|
@@ -56,10 +56,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
Dibi\Helpers::alias($config, 'database', 'file');
|
||||
$this->fmtDate = $config['formatDate'] ?? 'U';
|
||||
@@ -91,9 +90,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
$this->connection->close();
|
||||
}
|
||||
@@ -102,10 +100,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
if ($this->dbcharset !== NULL) {
|
||||
$sql = iconv($this->charset, $this->dbcharset . '//IGNORE', $sql);
|
||||
@@ -122,10 +119,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Dibi\DriverException
|
||||
*/
|
||||
public static function createException($message, $code, $sql)
|
||||
public static function createException(string $message, $code, string $sql): Dibi\DriverException
|
||||
{
|
||||
if ($code !== 19) {
|
||||
return new Dibi\DriverException($message, $code, $sql);
|
||||
@@ -154,9 +148,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return $this->connection->changes();
|
||||
}
|
||||
@@ -164,9 +157,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
return $this->connection->lastInsertRowID();
|
||||
}
|
||||
@@ -175,10 +167,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "SAVEPOINT $savepoint" : 'BEGIN');
|
||||
}
|
||||
@@ -187,10 +178,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT');
|
||||
}
|
||||
@@ -199,10 +189,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
$this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK');
|
||||
}
|
||||
@@ -210,9 +199,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection resource.
|
||||
* @return SQLite3
|
||||
*/
|
||||
public function getResource()
|
||||
public function getResource(): SQLite3
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
@@ -220,9 +208,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return new SqliteReflector($this);
|
||||
}
|
||||
@@ -230,10 +217,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param \SQLite3Result
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver(\SQLite3Result $resource)
|
||||
public function createResultDriver(\SQLite3Result $resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -246,40 +231,26 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . $this->connection->escapeString($value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "X'" . bin2hex((string) $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
return '[' . strtr($value, '[]', ' ') . ']';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -287,9 +258,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -300,9 +270,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -313,11 +282,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$value = addcslashes($this->connection->escapeString($value), '%_\\');
|
||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'") . " ESCAPE '\\'";
|
||||
@@ -326,10 +292,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -337,12 +301,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit < 0 || $offset < 0) {
|
||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||
@@ -359,7 +319,6 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -369,10 +328,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
* @throws Dibi\NotSupportedException
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Row count is not available for unbuffered queries.');
|
||||
}
|
||||
@@ -381,9 +339,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
$row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM);
|
||||
if (!$row) {
|
||||
@@ -406,11 +363,9 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws Dibi\NotSupportedException
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Cannot seek an unbuffered result set.');
|
||||
}
|
||||
@@ -418,9 +373,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
$this->resultSet->finalize();
|
||||
$this->resultSet = NULL;
|
||||
@@ -429,9 +383,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$count = $this->resultSet->numColumns();
|
||||
$columns = [];
|
||||
@@ -450,9 +403,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the result set resource.
|
||||
* @return \SQLite3Result|NULL
|
||||
*/
|
||||
public function getResultResource()
|
||||
public function getResultResource(): ?\SQLite3Result
|
||||
{
|
||||
$this->autoFree = FALSE;
|
||||
return $this->resultSet;
|
||||
@@ -465,11 +417,10 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Registers an user defined function for use in SQL statements.
|
||||
* @param string function name
|
||||
* @param mixed callback
|
||||
* @param mixed
|
||||
* @param int num of arguments
|
||||
* @return void
|
||||
*/
|
||||
public function registerFunction($name, callable $callback, $numArgs = -1)
|
||||
public function registerFunction(string $name, callable $callback, int $numArgs = -1): void
|
||||
{
|
||||
$this->connection->createFunction($name, $callback, $numArgs);
|
||||
}
|
||||
@@ -481,9 +432,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
||||
* @param mixed callback called for each row of the result set
|
||||
* @param mixed callback called to aggregate the "stepped" data from each row
|
||||
* @param int num of arguments
|
||||
* @return void
|
||||
*/
|
||||
public function registerAggregateFunction($name, callable $rowCallback, callable $agrCallback, $numArgs = -1)
|
||||
public function registerAggregateFunction(string $name, callable $rowCallback, callable $agrCallback, int $numArgs = -1): void
|
||||
{
|
||||
$this->connection->createAggregate($name, $rowCallback, $agrCallback, $numArgs);
|
||||
}
|
||||
|
@@ -30,9 +30,8 @@ class SqliteReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = $this->driver->query("
|
||||
SELECT name, type = 'view' as view FROM sqlite_master WHERE type IN ('table', 'view')
|
||||
@@ -50,10 +49,8 @@ class SqliteReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})");
|
||||
$columns = [];
|
||||
@@ -78,10 +75,8 @@ class SqliteReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})");
|
||||
$indexes = [];
|
||||
@@ -129,10 +124,8 @@ class SqliteReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})");
|
||||
$keys = [];
|
||||
|
@@ -58,10 +58,9 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
public function connect(array &$config): void
|
||||
{
|
||||
Helpers::alias($config, 'options|UID', 'username');
|
||||
Helpers::alias($config, 'options|PWD', 'password');
|
||||
@@ -93,9 +92,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(): void
|
||||
{
|
||||
@sqlsrv_close($this->connection); // @ - connection can be already disconnected
|
||||
}
|
||||
@@ -104,10 +102,9 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\ResultDriver|NULL
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function query($sql)
|
||||
public function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
$this->affectedRows = NULL;
|
||||
$res = sqlsrv_query($this->connection, $sql);
|
||||
@@ -126,9 +123,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
public function getAffectedRows(): ?int
|
||||
{
|
||||
return $this->affectedRows;
|
||||
}
|
||||
@@ -136,9 +132,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
public function getInsertId($sequence)
|
||||
public function getInsertId(?string $sequence): ?int
|
||||
{
|
||||
$res = sqlsrv_query($this->connection, 'SELECT SCOPE_IDENTITY()');
|
||||
if (is_resource($res)) {
|
||||
@@ -152,10 +147,9 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function begin($savepoint = NULL)
|
||||
public function begin(string $savepoint = NULL): void
|
||||
{
|
||||
sqlsrv_begin_transaction($this->connection);
|
||||
}
|
||||
@@ -164,10 +158,9 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function commit($savepoint = NULL)
|
||||
public function commit(string $savepoint = NULL): void
|
||||
{
|
||||
sqlsrv_commit($this->connection);
|
||||
}
|
||||
@@ -176,10 +169,9 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\DriverException
|
||||
*/
|
||||
public function rollback($savepoint = NULL)
|
||||
public function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
sqlsrv_rollback($this->connection);
|
||||
}
|
||||
@@ -197,9 +189,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Dibi\Reflector
|
||||
*/
|
||||
public function getReflector()
|
||||
public function getReflector(): Dibi\Reflector
|
||||
{
|
||||
return new SqlsrvReflector($this);
|
||||
}
|
||||
@@ -208,9 +199,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource
|
||||
* @return Dibi\ResultDriver
|
||||
*/
|
||||
public function createResultDriver($resource)
|
||||
public function createResultDriver($resource): Dibi\ResultDriver
|
||||
{
|
||||
$res = clone $this;
|
||||
$res->resultSet = $resource;
|
||||
@@ -223,41 +213,27 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
public function escapeText($value)
|
||||
public function escapeText(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBinary($value)
|
||||
public function escapeBinary(string $value): string
|
||||
{
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function escapeIdentifier($value)
|
||||
public function escapeIdentifier(string $value): string
|
||||
{
|
||||
// @see https://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||
return '[' . str_replace(']', ']]', $value) . ']';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function escapeBool($value)
|
||||
public function escapeBool(bool $value): string
|
||||
{
|
||||
return $value ? '1' : '0';
|
||||
}
|
||||
@@ -265,9 +241,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDate($value)
|
||||
public function escapeDate($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -278,9 +253,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeDateTime($value)
|
||||
public function escapeDateTime($value): string
|
||||
{
|
||||
if (!$value instanceof \DateTimeInterface) {
|
||||
$value = new Dibi\DateTime($value);
|
||||
@@ -291,11 +265,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function escapeLike($value, $pos)
|
||||
public function escapeLike(string $value, int $pos): string
|
||||
{
|
||||
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||
@@ -304,10 +275,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function unescapeBinary($value)
|
||||
public function unescapeBinary(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
@@ -315,12 +284,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
public function applyLimit(&$sql, $limit, $offset)
|
||||
public function applyLimit(string &$sql, ?int $limit, ?int $offset): void
|
||||
{
|
||||
if ($limit < 0 || $offset < 0) {
|
||||
throw new Dibi\NotSupportedException('Negative offset or limit.');
|
||||
@@ -348,7 +313,6 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Automatically frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
@@ -358,9 +322,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
public function getRowCount()
|
||||
public function getRowCount(): int
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Row count is not available for unbuffered queries.');
|
||||
}
|
||||
@@ -369,9 +332,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
*/
|
||||
public function fetch($assoc)
|
||||
public function fetch(bool $assoc): ?array
|
||||
{
|
||||
return sqlsrv_fetch_array($this->resultSet, $assoc ? SQLSRV_FETCH_ASSOC : SQLSRV_FETCH_NUMERIC);
|
||||
}
|
||||
@@ -379,10 +341,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
public function seek(int $row): bool
|
||||
{
|
||||
throw new Dibi\NotSupportedException('Cannot seek an unbuffered result set.');
|
||||
}
|
||||
@@ -390,9 +350,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
public function free()
|
||||
public function free(): void
|
||||
{
|
||||
sqlsrv_free_stmt($this->resultSet);
|
||||
$this->resultSet = NULL;
|
||||
@@ -401,9 +360,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a result set.
|
||||
* @return array
|
||||
*/
|
||||
public function getResultColumns()
|
||||
public function getResultColumns(): array
|
||||
{
|
||||
$columns = [];
|
||||
foreach ((array) sqlsrv_field_metadata($this->resultSet) as $fieldMetadata) {
|
||||
|
@@ -30,9 +30,8 @@ class SqlsrvReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns list of tables.
|
||||
* @return array
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$res = $this->driver->query("SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE [TABLE_SCHEMA] = 'dbo'");
|
||||
$tables = [];
|
||||
@@ -48,10 +47,8 @@ class SqlsrvReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns($table)
|
||||
public function getColumns(string $table): array
|
||||
{
|
||||
$res = $this->driver->query("
|
||||
SELECT c.name as COLUMN_NAME, c.is_identity AS AUTO_INCREMENT
|
||||
@@ -100,10 +97,8 @@ class SqlsrvReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
public function getIndexes(string $table): array
|
||||
{
|
||||
$keyUsagesRes = $this->driver->query(sprintf("EXEC [sys].[sp_helpindex] @objname = N%s", $this->driver->escapeText($table)));
|
||||
$keyUsages = [];
|
||||
@@ -125,10 +120,8 @@ class SqlsrvReflector implements Dibi\Reflector
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
public function getForeignKeys($table)
|
||||
public function getForeignKeys(string $table): array
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
|
@@ -102,9 +102,6 @@ class Fluent implements IDataSource
|
||||
private static $normalizer;
|
||||
|
||||
|
||||
/**
|
||||
* @param Connection
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
@@ -119,9 +116,8 @@ class Fluent implements IDataSource
|
||||
* Appends new argument to the clause.
|
||||
* @param string clause name
|
||||
* @param array arguments
|
||||
* @return self
|
||||
*/
|
||||
public function __call($clause, $args)
|
||||
public function __call(string $clause, array $args): self
|
||||
{
|
||||
$clause = self::$normalizer->$clause;
|
||||
|
||||
@@ -207,9 +203,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Switch to a clause.
|
||||
* @param string clause name
|
||||
* @return self
|
||||
*/
|
||||
public function clause($clause)
|
||||
public function clause(string $clause): self
|
||||
{
|
||||
$this->cursor = &$this->clauses[self::$normalizer->$clause];
|
||||
if ($this->cursor === NULL) {
|
||||
@@ -223,9 +218,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Removes a clause.
|
||||
* @param string clause name
|
||||
* @return self
|
||||
*/
|
||||
public function removeClause($clause)
|
||||
public function removeClause(string $clause): self
|
||||
{
|
||||
$this->clauses[self::$normalizer->$clause] = NULL;
|
||||
return $this;
|
||||
@@ -235,10 +229,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Change a SQL flag.
|
||||
* @param string flag name
|
||||
* @param bool value
|
||||
* @return self
|
||||
*/
|
||||
public function setFlag($flag, $value = TRUE)
|
||||
public function setFlag(string $flag, bool $value = TRUE): self
|
||||
{
|
||||
$flag = strtoupper($flag);
|
||||
if ($value) {
|
||||
@@ -253,9 +245,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Is a flag set?
|
||||
* @param string flag name
|
||||
* @return bool
|
||||
*/
|
||||
final public function getFlag($flag)
|
||||
final public function getFlag(string $flag): bool
|
||||
{
|
||||
return isset($this->flags[strtoupper($flag)]);
|
||||
}
|
||||
@@ -263,9 +254,8 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns SQL command.
|
||||
* @return string
|
||||
*/
|
||||
final public function getCommand()
|
||||
final public function getCommand(): string
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
@@ -273,9 +263,8 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns the dibi connection.
|
||||
* @return Connection
|
||||
*/
|
||||
final public function getConnection()
|
||||
final public function getConnection(): Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
@@ -283,11 +272,9 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Adds Result setup.
|
||||
* @param string method
|
||||
* @param mixed args
|
||||
* @return self
|
||||
*/
|
||||
public function setupResult($method)
|
||||
public function setupResult(string $method): self
|
||||
{
|
||||
$this->setups[] = func_get_args();
|
||||
return $this;
|
||||
@@ -347,11 +334,8 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Fetches all records from table.
|
||||
* @param int offset
|
||||
* @param int limit
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAll($offset = NULL, $limit = NULL)
|
||||
public function fetchAll(int $offset = NULL, int $limit = NULL): array
|
||||
{
|
||||
return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->fetchAll();
|
||||
}
|
||||
@@ -360,9 +344,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Fetches all records from table and returns associative tree.
|
||||
* @param string associative descriptor
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAssoc($assoc)
|
||||
public function fetchAssoc(string $assoc): array
|
||||
{
|
||||
return $this->query($this->_export())->fetchAssoc($assoc);
|
||||
}
|
||||
@@ -371,10 +354,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Fetches all records from table like $key => $value pairs.
|
||||
* @param string associative key
|
||||
* @param string value
|
||||
* @return array
|
||||
*/
|
||||
public function fetchPairs($key = NULL, $value = NULL)
|
||||
public function fetchPairs(string $key = NULL, string $value = NULL): array
|
||||
{
|
||||
return $this->query($this->_export())->fetchPairs($key, $value);
|
||||
}
|
||||
@@ -382,11 +363,8 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Required by the IteratorAggregate interface.
|
||||
* @param int offset
|
||||
* @param int limit
|
||||
* @return ResultIterator
|
||||
*/
|
||||
public function getIterator($offset = NULL, $limit = NULL)
|
||||
public function getIterator(int $offset = NULL, int $limit = NULL): ResultIterator
|
||||
{
|
||||
return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->getIterator();
|
||||
}
|
||||
@@ -395,18 +373,14 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Generates and prints SQL query or it's part.
|
||||
* @param string clause name
|
||||
* @return bool
|
||||
*/
|
||||
public function test($clause = NULL)
|
||||
public function test(string $clause = NULL): bool
|
||||
{
|
||||
return $this->connection->test($this->_export($clause));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return (int) $this->query([
|
||||
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') [data]',
|
||||
@@ -414,10 +388,7 @@ class Fluent implements IDataSource
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
*/
|
||||
private function query($args)
|
||||
private function query($args): Result
|
||||
{
|
||||
$res = $this->connection->query($args);
|
||||
foreach ($this->setups as $setup) {
|
||||
@@ -431,10 +402,7 @@ class Fluent implements IDataSource
|
||||
/********************* exporting ****************d*g**/
|
||||
|
||||
|
||||
/**
|
||||
* @return DataSource
|
||||
*/
|
||||
public function toDataSource()
|
||||
public function toDataSource(): DataSource
|
||||
{
|
||||
return new DataSource($this->connection->translate($this->_export()), $this->connection);
|
||||
}
|
||||
@@ -442,9 +410,8 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns SQL query.
|
||||
* @return string
|
||||
*/
|
||||
final public function __toString()
|
||||
final public function __toString(): string
|
||||
{
|
||||
try {
|
||||
return $this->connection->translate($this->_export());
|
||||
@@ -457,9 +424,8 @@ class Fluent implements IDataSource
|
||||
/**
|
||||
* Generates parameters for Translator.
|
||||
* @param string clause name
|
||||
* @return array
|
||||
*/
|
||||
protected function _export($clause = NULL, $args = [])
|
||||
protected function _export(string $clause = NULL, array $args = []): array
|
||||
{
|
||||
if ($clause === NULL) {
|
||||
$data = $this->clauses;
|
||||
@@ -495,11 +461,9 @@ class Fluent implements IDataSource
|
||||
|
||||
/**
|
||||
* Format camelCase clause name to UPPER CASE.
|
||||
* @param string
|
||||
* @return string
|
||||
* @internal
|
||||
*/
|
||||
public static function _formatClause($s)
|
||||
public static function _formatClause(string $s): string
|
||||
{
|
||||
if ($s === 'order' || $s === 'group') {
|
||||
$s .= 'By';
|
||||
|
@@ -19,9 +19,8 @@ class Helpers
|
||||
* Prints out a syntax highlighted version of the SQL command or Result.
|
||||
* @param string|Result
|
||||
* @param bool return output instead of printing it?
|
||||
* @return string
|
||||
*/
|
||||
public static function dump($sql = NULL, $return = FALSE)
|
||||
public static function dump($sql = NULL, bool $return = FALSE): string
|
||||
{
|
||||
ob_start();
|
||||
if ($sql instanceof Result && PHP_SAPI === 'cli') {
|
||||
@@ -135,10 +134,9 @@ class Helpers
|
||||
|
||||
/**
|
||||
* Finds the best suggestion.
|
||||
* @return string|NULL
|
||||
* @internal
|
||||
*/
|
||||
public static function getSuggestion(array $items, $value)
|
||||
public static function getSuggestion(array $items, $value): ?string
|
||||
{
|
||||
$best = NULL;
|
||||
$min = (strlen($value) / 4 + 1) * 10 + .1;
|
||||
@@ -174,11 +172,9 @@ class Helpers
|
||||
|
||||
/**
|
||||
* Heuristic type detection.
|
||||
* @param string
|
||||
* @return string|NULL
|
||||
* @internal
|
||||
*/
|
||||
public static function detectType($type)
|
||||
public static function detectType(string $type): ?string
|
||||
{
|
||||
static $patterns = [
|
||||
'^_' => Type::TEXT, // PostgreSQL arrays
|
||||
@@ -216,11 +212,9 @@ class Helpers
|
||||
/**
|
||||
* Apply configuration alias or default values.
|
||||
* @param array connect configuration
|
||||
* @param string key
|
||||
* @param string alias key
|
||||
* @return void
|
||||
* @param string $alias alias key
|
||||
*/
|
||||
public static function alias(&$config, $key, $alias)
|
||||
public static function alias(array &$config, string $key, string $alias): void
|
||||
{
|
||||
$foo = &$config;
|
||||
foreach (explode('|', $key) as $key) {
|
||||
@@ -238,7 +232,7 @@ class Helpers
|
||||
* Import SQL dump from file.
|
||||
* @return int count of sql commands
|
||||
*/
|
||||
public static function loadFromFile(Connection $connection, $file, callable $onProgress = NULL)
|
||||
public static function loadFromFile(Connection $connection, $file, callable $onProgress = NULL): int
|
||||
{
|
||||
@set_time_limit(0); // intentionally @
|
||||
|
||||
|
@@ -25,10 +25,7 @@ class Literal
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ class FileLogger
|
||||
public $filter;
|
||||
|
||||
|
||||
public function __construct($file, $filter = NULL)
|
||||
public function __construct(string $file, int $filter = NULL)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->filter = $filter ? (int) $filter : Dibi\Event::QUERY;
|
||||
@@ -33,9 +33,8 @@ class FileLogger
|
||||
|
||||
/**
|
||||
* After event notification.
|
||||
* @return void
|
||||
*/
|
||||
public function logEvent(Dibi\Event $event)
|
||||
public function logEvent(Dibi\Event $event): void
|
||||
{
|
||||
if (($event->type & $this->filter) === 0) {
|
||||
return;
|
||||
|
@@ -39,16 +39,13 @@ class FirePhpLogger
|
||||
private static $fireTable = [['Time', 'SQL Statement', 'Rows', 'Connection']];
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAvailable()
|
||||
public static function isAvailable(): bool
|
||||
{
|
||||
return isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP/');
|
||||
}
|
||||
|
||||
|
||||
public function __construct($filter = NULL)
|
||||
public function __construct(int $filter = NULL)
|
||||
{
|
||||
$this->filter = $filter ? (int) $filter : Dibi\Event::QUERY;
|
||||
}
|
||||
@@ -56,9 +53,8 @@ class FirePhpLogger
|
||||
|
||||
/**
|
||||
* After event notification.
|
||||
* @return void
|
||||
*/
|
||||
public function logEvent(Dibi\Event $event)
|
||||
public function logEvent(Dibi\Event $event): void
|
||||
{
|
||||
if (headers_sent() || ($event->type & $this->filter) === 0 || count(self::$fireTable) > self::$maxQueries) {
|
||||
return;
|
||||
|
@@ -43,37 +43,25 @@ class Column
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->info['name'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFullName()
|
||||
public function getFullName(): string
|
||||
{
|
||||
return $this->info['fullname'] ?? NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable()
|
||||
public function hasTable(): bool
|
||||
{
|
||||
return !empty($this->info['table']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Table
|
||||
*/
|
||||
public function getTable()
|
||||
public function getTable(): Table
|
||||
{
|
||||
if (empty($this->info['table']) || !$this->reflector) {
|
||||
throw new Dibi\Exception("Table is unknown or not available.");
|
||||
@@ -82,64 +70,43 @@ class Column
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function getTableName()
|
||||
public function getTableName(): ?string
|
||||
{
|
||||
return isset($this->info['table']) && $this->info['table'] != NULL ? $this->info['table'] : NULL; // intentionally ==
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): string
|
||||
{
|
||||
return Dibi\Helpers::getTypeCache()->{$this->info['nativetype']};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNativeType()
|
||||
public function getNativeType(): string
|
||||
{
|
||||
return $this->info['nativetype'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function getSize()
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return isset($this->info['size']) ? (int) $this->info['size'] : NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool|NULL
|
||||
*/
|
||||
public function isUnsigned()
|
||||
public function isUnsigned(): ?bool
|
||||
{
|
||||
return isset($this->info['unsigned']) ? (bool) $this->info['unsigned'] : NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool|NULL
|
||||
*/
|
||||
public function isNullable()
|
||||
public function isNullable(): ?bool
|
||||
{
|
||||
return isset($this->info['nullable']) ? (bool) $this->info['nullable'] : NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool|NULL
|
||||
*/
|
||||
public function isAutoIncrement()
|
||||
public function isAutoIncrement(): ?bool
|
||||
{
|
||||
return isset($this->info['autoincrement']) ? (bool) $this->info['autoincrement'] : NULL;
|
||||
}
|
||||
@@ -155,10 +122,9 @@ class Column
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVendorInfo($key)
|
||||
public function getVendorInfo(string $key)
|
||||
{
|
||||
return $this->info['vendor'][$key] ?? NULL;
|
||||
}
|
||||
|
@@ -38,10 +38,7 @@ class Database
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
@@ -50,7 +47,7 @@ class Database
|
||||
/**
|
||||
* @return Table[]
|
||||
*/
|
||||
public function getTables()
|
||||
public function getTables(): array
|
||||
{
|
||||
$this->init();
|
||||
return array_values($this->tables);
|
||||
@@ -60,7 +57,7 @@ class Database
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTableNames()
|
||||
public function getTableNames(): array
|
||||
{
|
||||
$this->init();
|
||||
$res = [];
|
||||
@@ -71,11 +68,7 @@ class Database
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return Table
|
||||
*/
|
||||
public function getTable($name)
|
||||
public function getTable(string $name): Table
|
||||
{
|
||||
$this->init();
|
||||
$l = strtolower($name);
|
||||
@@ -88,21 +81,14 @@ class Database
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable($name)
|
||||
public function hasTable(string $name): bool
|
||||
{
|
||||
$this->init();
|
||||
return isset($this->tables[strtolower($name)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function init()
|
||||
protected function init(): void
|
||||
{
|
||||
if ($this->tables === NULL) {
|
||||
$this->tables = [];
|
||||
|
@@ -34,19 +34,13 @@ class ForeignKey
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getReferences()
|
||||
public function getReferences(): array
|
||||
{
|
||||
return $this->references;
|
||||
}
|
||||
|
@@ -32,37 +32,25 @@ class Index
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->info['name'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns()
|
||||
public function getColumns(): array
|
||||
{
|
||||
return $this->info['columns'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUnique()
|
||||
public function isUnique(): bool
|
||||
{
|
||||
return !empty($this->info['unique']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrimary()
|
||||
public function isPrimary(): bool
|
||||
{
|
||||
return !empty($this->info['primary']);
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ class Result
|
||||
/**
|
||||
* @return Column[]
|
||||
*/
|
||||
public function getColumns()
|
||||
public function getColumns(): array
|
||||
{
|
||||
$this->initColumns();
|
||||
return array_values($this->columns);
|
||||
@@ -47,10 +47,9 @@ class Result
|
||||
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string[]
|
||||
*/
|
||||
public function getColumnNames($fullNames = FALSE)
|
||||
public function getColumnNames(bool $fullNames = FALSE): array
|
||||
{
|
||||
$this->initColumns();
|
||||
$res = [];
|
||||
@@ -61,11 +60,7 @@ class Result
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return Column
|
||||
*/
|
||||
public function getColumn($name)
|
||||
public function getColumn(string $name): Column
|
||||
{
|
||||
$this->initColumns();
|
||||
$l = strtolower($name);
|
||||
@@ -78,21 +73,14 @@ class Result
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumn($name)
|
||||
public function hasColumn(string $name): bool
|
||||
{
|
||||
$this->initColumns();
|
||||
return isset($this->names[strtolower($name)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function initColumns()
|
||||
protected function initColumns(): void
|
||||
{
|
||||
if ($this->columns === NULL) {
|
||||
$this->columns = [];
|
||||
|
@@ -55,19 +55,13 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isView()
|
||||
public function isView(): bool
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
@@ -76,7 +70,7 @@ class Table
|
||||
/**
|
||||
* @return Column[]
|
||||
*/
|
||||
public function getColumns()
|
||||
public function getColumns(): array
|
||||
{
|
||||
$this->initColumns();
|
||||
return array_values($this->columns);
|
||||
@@ -86,7 +80,7 @@ class Table
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getColumnNames()
|
||||
public function getColumnNames(): array
|
||||
{
|
||||
$this->initColumns();
|
||||
$res = [];
|
||||
@@ -97,11 +91,7 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return Column
|
||||
*/
|
||||
public function getColumn($name)
|
||||
public function getColumn(string $name): Column
|
||||
{
|
||||
$this->initColumns();
|
||||
$l = strtolower($name);
|
||||
@@ -114,11 +104,7 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumn($name)
|
||||
public function hasColumn(string $name): bool
|
||||
{
|
||||
$this->initColumns();
|
||||
return isset($this->columns[strtolower($name)]);
|
||||
@@ -128,7 +114,7 @@ class Table
|
||||
/**
|
||||
* @return ForeignKey[]
|
||||
*/
|
||||
public function getForeignKeys()
|
||||
public function getForeignKeys(): array
|
||||
{
|
||||
$this->initForeignKeys();
|
||||
return $this->foreignKeys;
|
||||
@@ -138,27 +124,21 @@ class Table
|
||||
/**
|
||||
* @return Index[]
|
||||
*/
|
||||
public function getIndexes()
|
||||
public function getIndexes(): array
|
||||
{
|
||||
$this->initIndexes();
|
||||
return $this->indexes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Index
|
||||
*/
|
||||
public function getPrimaryKey()
|
||||
public function getPrimaryKey(): Index
|
||||
{
|
||||
$this->initIndexes();
|
||||
return $this->primaryKey;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function initColumns()
|
||||
protected function initColumns(): void
|
||||
{
|
||||
if ($this->columns === NULL) {
|
||||
$this->columns = [];
|
||||
@@ -169,10 +149,7 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function initIndexes()
|
||||
protected function initIndexes(): void
|
||||
{
|
||||
if ($this->indexes === NULL) {
|
||||
$this->initColumns();
|
||||
@@ -190,10 +167,7 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function initForeignKeys()
|
||||
protected function initForeignKeys(): void
|
||||
{
|
||||
throw new Dibi\NotImplementedException;
|
||||
}
|
||||
|
@@ -52,10 +52,7 @@ class Result implements IDataSource
|
||||
private $formats = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param ResultDriver
|
||||
*/
|
||||
public function __construct($driver)
|
||||
public function __construct(ResultDriver $driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->detectTypes();
|
||||
@@ -64,9 +61,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @return void
|
||||
*/
|
||||
final public function free()
|
||||
final public function free(): void
|
||||
{
|
||||
if ($this->driver !== NULL) {
|
||||
$this->driver->free();
|
||||
@@ -77,10 +73,9 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Safe access to property $driver.
|
||||
* @return ResultDriver
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
final public function getResultDriver()
|
||||
final public function getResultDriver(): ResultDriver
|
||||
{
|
||||
if ($this->driver === NULL) {
|
||||
throw new \RuntimeException('Result-set was released from memory.');
|
||||
@@ -95,11 +90,9 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws Exception
|
||||
*/
|
||||
final public function seek($row)
|
||||
final public function seek(int $row): bool
|
||||
{
|
||||
return ($row !== 0 || $this->fetched) ? (bool) $this->getResultDriver()->seek($row) : TRUE;
|
||||
}
|
||||
@@ -107,9 +100,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Required by the Countable interface.
|
||||
* @return int
|
||||
*/
|
||||
final public function count()
|
||||
final public function count(): int
|
||||
{
|
||||
return $this->getResultDriver()->getRowCount();
|
||||
}
|
||||
@@ -117,9 +109,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
final public function getRowCount()
|
||||
final public function getRowCount(): int
|
||||
{
|
||||
return $this->getResultDriver()->getRowCount();
|
||||
}
|
||||
@@ -127,9 +118,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Required by the IteratorAggregate interface.
|
||||
* @return ResultIterator
|
||||
*/
|
||||
final public function getIterator()
|
||||
final public function getIterator(): ResultIterator
|
||||
{
|
||||
return new ResultIterator($this);
|
||||
}
|
||||
@@ -140,10 +130,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Set fetched object class. This class should extend the Row class.
|
||||
* @param string
|
||||
* @return self
|
||||
*/
|
||||
public function setRowClass($class)
|
||||
public function setRowClass(string $class): self
|
||||
{
|
||||
$this->rowClass = $class;
|
||||
return $this;
|
||||
@@ -152,9 +140,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns fetched object class name.
|
||||
* @return string
|
||||
*/
|
||||
public function getRowClass()
|
||||
public function getRowClass(): string
|
||||
{
|
||||
return $this->rowClass;
|
||||
}
|
||||
@@ -162,9 +149,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Set a factory to create fetched object instances. These should extend the Row class.
|
||||
* @return self
|
||||
*/
|
||||
public function setRowFactory(callable $callback)
|
||||
public function setRowFactory(callable $callback): self
|
||||
{
|
||||
$this->rowFactory = $callback;
|
||||
return $this;
|
||||
@@ -174,9 +160,8 @@ class Result implements IDataSource
|
||||
/**
|
||||
* Fetches the row at current position, process optional type conversion.
|
||||
* and moves the internal cursor to the next position
|
||||
* @return Row|NULL
|
||||
*/
|
||||
final public function fetch()
|
||||
final public function fetch(): ?Row
|
||||
{
|
||||
$row = $this->getResultDriver()->fetch(TRUE);
|
||||
if ($row === NULL) {
|
||||
@@ -211,11 +196,9 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Fetches all records from table.
|
||||
* @param int offset
|
||||
* @param int limit
|
||||
* @return Row[]
|
||||
*/
|
||||
final public function fetchAll($offset = NULL, $limit = NULL)
|
||||
final public function fetchAll(int $offset = NULL, int $limit = NULL): array
|
||||
{
|
||||
$limit = $limit === NULL ? -1 : (int) $limit;
|
||||
$this->seek((int) $offset);
|
||||
@@ -245,10 +228,9 @@ class Result implements IDataSource
|
||||
* - associative descriptor: col1|col2->col3=col4
|
||||
* builds a tree: $tree[$val1][$val2]->col3[$val3] = val4
|
||||
* @param string associative descriptor
|
||||
* @return array
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
final public function fetchAssoc($assoc)
|
||||
final public function fetchAssoc(string $assoc): array
|
||||
{
|
||||
if (strpos($assoc, ',') !== FALSE) {
|
||||
return $this->oldFetchAssoc($assoc);
|
||||
@@ -393,11 +375,9 @@ class Result implements IDataSource
|
||||
/**
|
||||
* Fetches all records from table like $key => $value pairs.
|
||||
* @param string associative key
|
||||
* @param string value
|
||||
* @return array
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
final public function fetchPairs($key = NULL, $value = NULL)
|
||||
final public function fetchPairs(string $key = NULL, string $value = NULL): array
|
||||
{
|
||||
$this->seek(0);
|
||||
$row = $this->fetch();
|
||||
@@ -454,9 +434,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Autodetect column types.
|
||||
* @return void
|
||||
*/
|
||||
private function detectTypes()
|
||||
private function detectTypes(): void
|
||||
{
|
||||
$cache = Helpers::getTypeCache();
|
||||
try {
|
||||
@@ -470,10 +449,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Converts values to specified type and format.
|
||||
* @param array
|
||||
* @return void
|
||||
*/
|
||||
private function normalize(array &$row)
|
||||
private function normalize(array &$row): void
|
||||
{
|
||||
foreach ($this->types as $key => $type) {
|
||||
if (!isset($row[$key])) { // NULL
|
||||
@@ -528,9 +505,8 @@ class Result implements IDataSource
|
||||
* Define column type.
|
||||
* @param string column
|
||||
* @param string type (use constant Type::*)
|
||||
* @return self
|
||||
*/
|
||||
final public function setType($col, $type)
|
||||
final public function setType(string $col, string $type): self
|
||||
{
|
||||
$this->types[$col] = $type;
|
||||
return $this;
|
||||
@@ -539,9 +515,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns column type.
|
||||
* @return string
|
||||
*/
|
||||
final public function getType($col)
|
||||
final public function getType($col): string
|
||||
{
|
||||
return $this->types[$col] ?? NULL;
|
||||
}
|
||||
@@ -550,10 +525,8 @@ class Result implements IDataSource
|
||||
/**
|
||||
* Sets date format.
|
||||
* @param string
|
||||
* @param string|NULL format
|
||||
* @return self
|
||||
*/
|
||||
final public function setFormat($type, $format)
|
||||
final public function setFormat(string $type, ?string $format): self
|
||||
{
|
||||
$this->formats[$type] = $format;
|
||||
return $this;
|
||||
@@ -562,9 +535,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns data format.
|
||||
* @return string|NULL
|
||||
*/
|
||||
final public function getFormat($type)
|
||||
final public function getFormat($type): ?string
|
||||
{
|
||||
return $this->formats[$type] ?? NULL;
|
||||
}
|
||||
@@ -575,9 +547,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Returns a meta information about the current result set.
|
||||
* @return Reflection\Result
|
||||
*/
|
||||
public function getInfo()
|
||||
public function getInfo(): Reflection\Result
|
||||
{
|
||||
if ($this->meta === NULL) {
|
||||
$this->meta = new Reflection\Result($this->getResultDriver());
|
||||
@@ -589,7 +560,7 @@ class Result implements IDataSource
|
||||
/**
|
||||
* @return Reflection\Column[]
|
||||
*/
|
||||
final public function getColumns()
|
||||
final public function getColumns(): array
|
||||
{
|
||||
return $this->getInfo()->getColumns();
|
||||
}
|
||||
@@ -600,9 +571,8 @@ class Result implements IDataSource
|
||||
|
||||
/**
|
||||
* Displays complete result set as HTML or text table for debug purposes.
|
||||
* @return void
|
||||
*/
|
||||
final public function dump()
|
||||
final public function dump(): void
|
||||
{
|
||||
echo Helpers::dump($this);
|
||||
}
|
||||
|
@@ -34,9 +34,6 @@ class ResultIterator implements \Iterator, \Countable
|
||||
private $pointer;
|
||||
|
||||
|
||||
/**
|
||||
* @param Result
|
||||
*/
|
||||
public function __construct(Result $result)
|
||||
{
|
||||
$this->result = $result;
|
||||
@@ -45,9 +42,8 @@ class ResultIterator implements \Iterator, \Countable
|
||||
|
||||
/**
|
||||
* Rewinds the iterator to the first element.
|
||||
* @return void
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->pointer = 0;
|
||||
$this->result->seek(0);
|
||||
@@ -77,9 +73,8 @@ class ResultIterator implements \Iterator, \Countable
|
||||
|
||||
/**
|
||||
* Moves forward to next element.
|
||||
* @return void
|
||||
*/
|
||||
public function next()
|
||||
public function next(): void
|
||||
{
|
||||
$this->row = $this->result->fetch();
|
||||
$this->pointer++;
|
||||
@@ -88,9 +83,8 @@ class ResultIterator implements \Iterator, \Countable
|
||||
|
||||
/**
|
||||
* Checks if there is a current element after calls to rewind() or next().
|
||||
* @return bool
|
||||
*/
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
return !empty($this->row);
|
||||
}
|
||||
@@ -98,9 +92,8 @@ class ResultIterator implements \Iterator, \Countable
|
||||
|
||||
/**
|
||||
* Required by the Countable interface.
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->result->getRowCount();
|
||||
}
|
||||
|
@@ -30,11 +30,8 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
|
||||
|
||||
/**
|
||||
* Converts value to DateTime object.
|
||||
* @param string key
|
||||
* @param string format
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function asDateTime($key, $format = NULL)
|
||||
public function asDateTime(string $key, string $format = NULL): \DateTime
|
||||
{
|
||||
$time = $this[$key];
|
||||
if (!$time instanceof DateTime) {
|
||||
|
@@ -83,10 +83,7 @@ trait Strict
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
public function __isset($name): bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -105,10 +102,9 @@ trait Strict
|
||||
|
||||
/**
|
||||
* @param string method name
|
||||
* @param callable
|
||||
* @return mixed
|
||||
*/
|
||||
public static function extensionMethod($name, $callback = NULL)
|
||||
public static function extensionMethod(string $name, callable $callback = NULL)
|
||||
{
|
||||
if (strpos($name, '::') === FALSE) {
|
||||
$class = get_called_class();
|
||||
|
@@ -59,11 +59,9 @@ final class Translator
|
||||
|
||||
/**
|
||||
* Generates SQL. Can be called only once.
|
||||
* @param array
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function translate(array $args)
|
||||
public function translate(array $args): string
|
||||
{
|
||||
$args = array_values($args);
|
||||
while (count($args) === 1 && is_array($args[0])) { // implicit array expansion
|
||||
@@ -168,10 +166,8 @@ final class Translator
|
||||
/**
|
||||
* Apply modifier to single value.
|
||||
* @param mixed
|
||||
* @param string|NULL
|
||||
* @return string
|
||||
*/
|
||||
public function formatValue($value, $modifier)
|
||||
public function formatValue($value, ?string $modifier): string
|
||||
{
|
||||
if ($this->comment) {
|
||||
return '...';
|
||||
@@ -454,10 +450,8 @@ final class Translator
|
||||
|
||||
/**
|
||||
* PREG callback from translate() or formatValue().
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
private function cb($matches)
|
||||
private function cb(array $matches): string
|
||||
{
|
||||
// [1] => `ident`
|
||||
// [2] => [ident]
|
||||
@@ -586,10 +580,9 @@ final class Translator
|
||||
/**
|
||||
* Apply substitutions to indentifier and delimites it.
|
||||
* @param string indentifier
|
||||
* @return string
|
||||
* @internal
|
||||
*/
|
||||
public function delimite($value)
|
||||
public function delimite(string $value): string
|
||||
{
|
||||
$value = $this->connection->substitute($value);
|
||||
$parts = explode('.', $value);
|
||||
|
@@ -67,10 +67,9 @@ class dibi
|
||||
* Creates a new Connection object and connects it to specified database.
|
||||
* @param mixed connection parameters
|
||||
* @param string connection name
|
||||
* @return Dibi\Connection
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function connect($config = [], $name = '0')
|
||||
public static function connect(array $config = [], string $name = '0'): Dibi\Connection
|
||||
{
|
||||
return self::$connection = self::$registry[$name] = new Dibi\Connection($config, $name);
|
||||
}
|
||||
@@ -78,9 +77,8 @@ class dibi
|
||||
|
||||
/**
|
||||
* Disconnects from database (doesn't destroy Connection object).
|
||||
* @return void
|
||||
*/
|
||||
public static function disconnect()
|
||||
public static function disconnect(): void
|
||||
{
|
||||
self::getConnection()->disconnect();
|
||||
}
|
||||
@@ -88,9 +86,8 @@ class dibi
|
||||
|
||||
/**
|
||||
* Returns TRUE when connection was established.
|
||||
* @return bool
|
||||
*/
|
||||
public static function isConnected()
|
||||
public static function isConnected(): bool
|
||||
{
|
||||
return (self::$connection !== NULL) && self::$connection->isConnected();
|
||||
}
|
||||
@@ -99,10 +96,9 @@ class dibi
|
||||
/**
|
||||
* Retrieve active connection.
|
||||
* @param string connection registy name
|
||||
* @return Dibi\Connection
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function getConnection($name = NULL)
|
||||
public static function getConnection(string $name = NULL): Dibi\Connection
|
||||
{
|
||||
if ($name === NULL) {
|
||||
if (self::$connection === NULL) {
|
||||
@@ -122,10 +118,8 @@ class dibi
|
||||
|
||||
/**
|
||||
* Sets connection.
|
||||
* @param Dibi\Connection
|
||||
* @return Dibi\Connection
|
||||
*/
|
||||
public static function setConnection(Dibi\Connection $connection)
|
||||
public static function setConnection(Dibi\Connection $connection): Dibi\Connection
|
||||
{
|
||||
return self::$connection = $connection;
|
||||
}
|
||||
@@ -151,7 +145,7 @@ class dibi
|
||||
* @param string SQL statement.
|
||||
* @return Dibi\Result|int result set or number of affected rows
|
||||
*/
|
||||
public static function nativeQuery($sql)
|
||||
public static function nativeQuery(string $sql)
|
||||
{
|
||||
return self::getConnection()->nativeQuery($sql);
|
||||
}
|
||||
@@ -160,9 +154,8 @@ class dibi
|
||||
/**
|
||||
* Generates and prints SQL query - Monostate for Dibi\Connection::test().
|
||||
* @param mixed one or more arguments
|
||||
* @return bool
|
||||
*/
|
||||
public static function test(...$args)
|
||||
public static function test(...$args): bool
|
||||
{
|
||||
return self::getConnection()->test($args);
|
||||
}
|
||||
@@ -171,9 +164,8 @@ class dibi
|
||||
/**
|
||||
* Generates and returns SQL query as DataSource - Monostate for Dibi\Connection::test().
|
||||
* @param mixed one or more arguments
|
||||
* @return Dibi\DataSource
|
||||
*/
|
||||
public static function dataSource(...$args)
|
||||
public static function dataSource(...$args): Dibi\DataSource
|
||||
{
|
||||
return self::getConnection()->dataSource($args);
|
||||
}
|
||||
@@ -197,7 +189,7 @@ class dibi
|
||||
* @return Dibi\Row[]
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function fetchAll(...$args)
|
||||
public static function fetchAll(...$args): array
|
||||
{
|
||||
return self::getConnection()->query($args)->fetchAll();
|
||||
}
|
||||
@@ -218,10 +210,9 @@ class dibi
|
||||
/**
|
||||
* Executes SQL query and fetch pairs - Monostate for Dibi\Connection::query() & fetchPairs().
|
||||
* @param mixed one or more arguments
|
||||
* @return array
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function fetchPairs(...$args)
|
||||
public static function fetchPairs(...$args): array
|
||||
{
|
||||
return self::getConnection()->query($args)->fetchPairs();
|
||||
}
|
||||
@@ -230,10 +221,9 @@ class dibi
|
||||
/**
|
||||
* Gets the number of affected rows.
|
||||
* Monostate for Dibi\Connection::getAffectedRows()
|
||||
* @return int number of rows
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function getAffectedRows()
|
||||
public static function getAffectedRows(): int
|
||||
{
|
||||
return self::getConnection()->getAffectedRows();
|
||||
}
|
||||
@@ -241,10 +231,9 @@ class dibi
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows. Alias for getAffectedRows().
|
||||
* @return int number of rows
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function affectedRows()
|
||||
public static function affectedRows(): int
|
||||
{
|
||||
return self::getConnection()->getAffectedRows();
|
||||
}
|
||||
@@ -254,10 +243,9 @@ class dibi
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* Monostate for Dibi\Connection::getInsertId()
|
||||
* @param string optional sequence name
|
||||
* @return int
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function getInsertId($sequence = NULL)
|
||||
public static function getInsertId(string $sequence = NULL): int
|
||||
{
|
||||
return self::getConnection()->getInsertId($sequence);
|
||||
}
|
||||
@@ -266,10 +254,9 @@ class dibi
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().
|
||||
* @param string optional sequence name
|
||||
* @return int
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function insertId($sequence = NULL)
|
||||
public static function insertId(string $sequence = NULL): int
|
||||
{
|
||||
return self::getConnection()->getInsertId($sequence);
|
||||
}
|
||||
@@ -278,10 +265,9 @@ class dibi
|
||||
/**
|
||||
* Begins a transaction - Monostate for Dibi\Connection::begin().
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function begin($savepoint = NULL)
|
||||
public static function begin(string $savepoint = NULL): void
|
||||
{
|
||||
self::getConnection()->begin($savepoint);
|
||||
}
|
||||
@@ -290,10 +276,9 @@ class dibi
|
||||
/**
|
||||
* Commits statements in a transaction - Monostate for Dibi\Connection::commit($savepoint = NULL).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function commit($savepoint = NULL)
|
||||
public static function commit(string $savepoint = NULL): void
|
||||
{
|
||||
self::getConnection()->commit($savepoint);
|
||||
}
|
||||
@@ -302,10 +287,9 @@ class dibi
|
||||
/**
|
||||
* Rollback changes in a transaction - Monostate for Dibi\Connection::rollback().
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws Dibi\Exception
|
||||
*/
|
||||
public static function rollback($savepoint = NULL)
|
||||
public static function rollback(string $savepoint = NULL): void
|
||||
{
|
||||
self::getConnection()->rollback($savepoint);
|
||||
}
|
||||
@@ -313,9 +297,8 @@ class dibi
|
||||
|
||||
/**
|
||||
* Gets a information about the current database - Monostate for Dibi\Connection::getDatabaseInfo().
|
||||
* @return Dibi\Reflection\Database
|
||||
*/
|
||||
public static function getDatabaseInfo()
|
||||
public static function getDatabaseInfo(): Dibi\Reflection\Database
|
||||
{
|
||||
return self::getConnection()->getDatabaseInfo();
|
||||
}
|
||||
@@ -326,7 +309,7 @@ class dibi
|
||||
* @param string filename
|
||||
* @return int count of sql commands
|
||||
*/
|
||||
public static function loadFile($file)
|
||||
public static function loadFile(string $file): int
|
||||
{
|
||||
return Dibi\Helpers::loadFromFile(self::getConnection(), $file);
|
||||
}
|
||||
@@ -335,10 +318,7 @@ class dibi
|
||||
/********************* fluent SQL builders ****************d*g**/
|
||||
|
||||
|
||||
/**
|
||||
* @return Dibi\Fluent
|
||||
*/
|
||||
public static function command()
|
||||
public static function command(): Dibi\Fluent
|
||||
{
|
||||
return self::getConnection()->command();
|
||||
}
|
||||
@@ -346,41 +326,26 @@ class dibi
|
||||
|
||||
/**
|
||||
* @param mixed column name
|
||||
* @return Dibi\Fluent
|
||||
*/
|
||||
public static function select(...$args)
|
||||
public static function select(...$args): Dibi\Fluent
|
||||
{
|
||||
return self::getConnection()->select(...$args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @param array
|
||||
* @return Dibi\Fluent
|
||||
*/
|
||||
public static function update($table, $args)
|
||||
public static function update(string $table, array $args): Dibi\Fluent
|
||||
{
|
||||
return self::getConnection()->update($table, $args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @param array
|
||||
* @return Dibi\Fluent
|
||||
*/
|
||||
public static function insert($table, $args)
|
||||
public static function insert(string $table, array $args): Dibi\Fluent
|
||||
{
|
||||
return self::getConnection()->insert($table, $args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string table
|
||||
* @return Dibi\Fluent
|
||||
*/
|
||||
public static function delete($table)
|
||||
public static function delete(string $table): Dibi\Fluent
|
||||
{
|
||||
return self::getConnection()->delete($table);
|
||||
}
|
||||
@@ -391,9 +356,8 @@ class dibi
|
||||
|
||||
/**
|
||||
* Returns substitution hashmap - Monostate for Dibi\Connection::getSubstitutes().
|
||||
* @return Dibi\HashMap
|
||||
*/
|
||||
public static function getSubstitutes()
|
||||
public static function getSubstitutes(): Dibi\HashMap
|
||||
{
|
||||
return self::getConnection()->getSubstitutes();
|
||||
}
|
||||
@@ -406,9 +370,8 @@ class dibi
|
||||
* Prints out a syntax highlighted version of the SQL command or Result.
|
||||
* @param string|Result
|
||||
* @param bool return output instead of printing it?
|
||||
* @return string
|
||||
*/
|
||||
public static function dump($sql = NULL, $return = FALSE)
|
||||
public static function dump($sql = NULL, bool $return = FALSE): string
|
||||
{
|
||||
return Dibi\Helpers::dump($sql, $return);
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ class Exception extends \Exception
|
||||
* @param mixed
|
||||
* @param string SQL command
|
||||
*/
|
||||
public function __construct($message = '', $code = 0, $sql = NULL)
|
||||
public function __construct(string $message = '', $code = 0, string $sql = NULL)
|
||||
{
|
||||
parent::__construct($message);
|
||||
$this->code = $code;
|
||||
@@ -31,19 +31,13 @@ class Exception extends \Exception
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string The SQL passed to the constructor
|
||||
*/
|
||||
final public function getSql()
|
||||
final public function getSql(): ?string
|
||||
{
|
||||
return $this->sql;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string string represenation of exception with SQL command
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return parent::__toString() . ($this->sql ? "\nSQL: " . $this->sql : '');
|
||||
}
|
||||
@@ -65,7 +59,7 @@ class DriverException extends Exception
|
||||
class PcreException extends Exception
|
||||
{
|
||||
|
||||
public function __construct($message = '%msg.')
|
||||
public function __construct(string $message = '%msg.')
|
||||
{
|
||||
static $messages = [
|
||||
PREG_INTERNAL_ERROR => 'Internal error',
|
||||
@@ -105,7 +99,7 @@ class ProcedureException extends Exception
|
||||
* @param int Some code
|
||||
* @param string SQL command
|
||||
*/
|
||||
public function __construct($message = NULL, $code = 0, $severity = NULL, $sql = NULL)
|
||||
public function __construct(string $message = NULL, int $code = 0, string $severity = NULL, $sql = NULL)
|
||||
{
|
||||
parent::__construct($message, (int) $code, $sql);
|
||||
$this->severity = $severity;
|
||||
@@ -114,9 +108,8 @@ class ProcedureException extends Exception
|
||||
|
||||
/**
|
||||
* Gets the exception severity.
|
||||
* @return string
|
||||
*/
|
||||
public function getSeverity()
|
||||
public function getSeverity(): string
|
||||
{
|
||||
$this->severity;
|
||||
}
|
||||
|
@@ -26,62 +26,53 @@ interface Driver
|
||||
|
||||
/**
|
||||
* Connects to a database.
|
||||
* @param array
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
function connect(array &$config);
|
||||
function connect(array &$config): void;
|
||||
|
||||
/**
|
||||
* Disconnects from a database.
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
function disconnect();
|
||||
function disconnect(): void;
|
||||
|
||||
/**
|
||||
* Internal: Executes the SQL query.
|
||||
* @param string SQL statement.
|
||||
* @return ResultDriver|NULL
|
||||
* @throws DriverException
|
||||
*/
|
||||
function query($sql);
|
||||
function query(string $sql): ?ResultDriver;
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
|
||||
* @return int|NULL number of rows or NULL on error
|
||||
*/
|
||||
function getAffectedRows();
|
||||
function getAffectedRows(): ?int;
|
||||
|
||||
/**
|
||||
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
|
||||
* @return int|NULL int on success or NULL on failure
|
||||
*/
|
||||
function getInsertId($sequence);
|
||||
function getInsertId(?string $sequence): ?int;
|
||||
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws DriverException
|
||||
*/
|
||||
function begin($savepoint = NULL);
|
||||
function begin(string $savepoint = NULL): void;
|
||||
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws DriverException
|
||||
*/
|
||||
function commit($savepoint = NULL);
|
||||
function commit(string $savepoint = NULL): void;
|
||||
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optional savepoint name
|
||||
* @return void
|
||||
* @throws DriverException
|
||||
*/
|
||||
function rollback($savepoint = NULL);
|
||||
function rollback(string $savepoint = NULL): void;
|
||||
|
||||
/**
|
||||
* Returns the connection resource.
|
||||
@@ -91,63 +82,39 @@ interface Driver
|
||||
|
||||
/**
|
||||
* Returns the connection reflector.
|
||||
* @return Reflector
|
||||
*/
|
||||
function getReflector();
|
||||
function getReflector(): Reflector;
|
||||
|
||||
/**
|
||||
* Encodes data for use in a SQL statement.
|
||||
* @param string value
|
||||
* @return string encoded value
|
||||
*/
|
||||
function escapeText($value);
|
||||
function escapeText(string $value): string;
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function escapeBinary($value);
|
||||
function escapeBinary(string $value): string;
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function escapeIdentifier($value);
|
||||
function escapeIdentifier(string $value): string;
|
||||
|
||||
/**
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
function escapeBool($value);
|
||||
function escapeBool(bool $value): string;
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
function escapeDate($value);
|
||||
function escapeDate($value): string;
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface|string|int
|
||||
* @return string
|
||||
*/
|
||||
function escapeDateTime($value);
|
||||
function escapeDateTime($value): string;
|
||||
|
||||
/**
|
||||
* Encodes string for use in a LIKE statement.
|
||||
* @param string
|
||||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
function escapeLike($value, $pos);
|
||||
function escapeLike(string $value, int $pos): string;
|
||||
|
||||
/**
|
||||
* Injects LIMIT/OFFSET to the SQL query.
|
||||
* @param string
|
||||
* @param int|NULL
|
||||
* @param int|NULL
|
||||
* @return void
|
||||
*/
|
||||
function applyLimit(&$sql, $limit, $offset);
|
||||
function applyLimit(string &$sql, ?int $limit, ?int $offset): void;
|
||||
|
||||
}
|
||||
|
||||
@@ -160,9 +127,8 @@ interface ResultDriver
|
||||
|
||||
/**
|
||||
* Returns the number of rows in a result set.
|
||||
* @return int
|
||||
*/
|
||||
function getRowCount();
|
||||
function getRowCount(): int;
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
@@ -170,28 +136,26 @@ interface ResultDriver
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws Exception
|
||||
*/
|
||||
function seek($row);
|
||||
function seek(int $row): bool;
|
||||
|
||||
/**
|
||||
* Fetches the row at current position and moves the internal cursor to the next position.
|
||||
* @param bool TRUE for associative array, FALSE for numeric
|
||||
* @return array|NULL array on success, NULL if no next record
|
||||
* @internal
|
||||
*/
|
||||
function fetch($type);
|
||||
function fetch(bool $type): ?array;
|
||||
|
||||
/**
|
||||
* Frees the resources allocated for this result set.
|
||||
* @param resource result set resource
|
||||
* @return void
|
||||
*/
|
||||
function free();
|
||||
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();
|
||||
function getResultColumns(): array;
|
||||
|
||||
/**
|
||||
* Returns the result set resource.
|
||||
@@ -201,10 +165,8 @@ interface ResultDriver
|
||||
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function unescapeBinary($value);
|
||||
function unescapeBinary(string $value): string;
|
||||
|
||||
}
|
||||
|
||||
@@ -219,27 +181,23 @@ interface Reflector
|
||||
* Returns list of tables.
|
||||
* @return array of {name [, (bool) view ]}
|
||||
*/
|
||||
function getTables();
|
||||
function getTables(): array;
|
||||
|
||||
/**
|
||||
* Returns metadata for all columns in a table.
|
||||
* @param string
|
||||
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
|
||||
*/
|
||||
function getColumns($table);
|
||||
function getColumns(string $table): array;
|
||||
|
||||
/**
|
||||
* Returns metadata for all indexes in a table.
|
||||
* @param string
|
||||
* @return array of {name, (array of names) columns [, (bool) unique, (bool) primary ]}
|
||||
*/
|
||||
function getIndexes($table);
|
||||
function getIndexes(string $table): array;
|
||||
|
||||
/**
|
||||
* Returns metadata for all foreign keys in a table.
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
function getForeignKeys($table);
|
||||
function getForeignKeys(string $table): array;
|
||||
|
||||
}
|
||||
|
@@ -10,20 +10,20 @@ class MockDriver extends Dibi\Drivers\SqlsrvDriver
|
||||
function __construct()
|
||||
{}
|
||||
|
||||
function connect(array &$config)
|
||||
function connect(array & $config): void
|
||||
{}
|
||||
|
||||
function query($sql)
|
||||
function query(string $sql): ?Dibi\ResultDriver
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
function getResultColumns()
|
||||
function getResultColumns(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
function fetch($assoc)
|
||||
function fetch(bool $type): ?array
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user