diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index 48718a0e..6eba0d8c 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -317,7 +317,7 @@ class Connection { $this->connected || $this->connect(); $rows = $this->driver->getAffectedRows(); - if (!is_int($rows) || $rows < 0) { + if ($rows === NULL || $rows < 0) { throw new Exception('Cannot retrieve number of affected rows.'); } return $rows; @@ -531,7 +531,7 @@ class Connection /** * Executes SQL query and fetch result - shortcut for query() & fetch(). * @param mixed one or more arguments - * @return Row|FALSE + * @return Row|NULL * @throws Exception */ public function fetch(...$args) diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index eb9d227f..e2ef9f5e 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -168,7 +168,7 @@ class DataSource implements IDataSource /** * Generates, executes SQL query and fetches the single row. - * @return Row|FALSE + * @return Row|NULL */ public function fetch() { @@ -178,7 +178,7 @@ class DataSource implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, FALSE if no next record + * @return mixed value on success, NULL if no next record */ public function fetchSingle() { diff --git a/src/Dibi/Drivers/FirebirdDriver.php b/src/Dibi/Drivers/FirebirdDriver.php index e1ec7abb..ac2d7b7a 100644 --- a/src/Dibi/Drivers/FirebirdDriver.php +++ b/src/Dibi/Drivers/FirebirdDriver.php @@ -8,6 +8,7 @@ namespace Dibi\Drivers; use Dibi; +use Dibi\Helpers; /** @@ -62,7 +63,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function connect(array &$config) { - Dibi\Helpers::alias($config, 'database', 'db'); + Helpers::alias($config, 'database', 'db'); if (isset($config['resource'])) { $this->connection = $config['resource']; @@ -129,22 +130,22 @@ 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|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { - return ibase_affected_rows($this->connection); + return Helpers::false2Null(ibase_affected_rows($this->connection)); } /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @param string generator name - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { - return ibase_gen_id($sequence, 0, $this->connection); + return Helpers::false2Null(ibase_gen_id($sequence, 0, $this->connection)); } @@ -382,7 +383,7 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { @@ -398,7 +399,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } } - return $result; + return Helpers::false2Null($result); } diff --git a/src/Dibi/Drivers/MsSqlDriver.php b/src/Dibi/Drivers/MsSqlDriver.php index f6bcd4e6..627a0c69 100644 --- a/src/Dibi/Drivers/MsSqlDriver.php +++ b/src/Dibi/Drivers/MsSqlDriver.php @@ -104,17 +104,17 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver /** * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. - * @return int|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { - return mssql_rows_affected($this->connection); + return Dibi\Helpers::false2Null(mssql_rows_affected($this->connection)); } /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { @@ -123,7 +123,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver $row = mssql_fetch_row($res); return $row[0]; } - return FALSE; + return NULL; } @@ -338,18 +338,18 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { - return mssql_fetch_array($this->resultSet, $assoc ? MSSQL_ASSOC : MSSQL_NUM); + return Dibi\Helpers::false2Null(mssql_fetch_array($this->resultSet, $assoc ? MSSQL_ASSOC : MSSQL_NUM)); } /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @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) { diff --git a/src/Dibi/Drivers/MsSqlReflector.php b/src/Dibi/Drivers/MsSqlReflector.php index 52cc9fd4..84d3c1ac 100644 --- a/src/Dibi/Drivers/MsSqlReflector.php +++ b/src/Dibi/Drivers/MsSqlReflector.php @@ -57,7 +57,7 @@ class MsSqlReflector implements Dibi\Reflector public function getTableCount($table, $fallback = TRUE) { if (empty($table)) { - return FALSE; + return NULL; } $result = $this->driver->query(" SELECT MAX(rowcnt) @@ -71,7 +71,7 @@ class MsSqlReflector implements Dibi\Reflector $row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(FALSE); $count = intval($row[0]); } else { - $count = FALSE; + $count = NULL; } } else { $count = intval($row[0]); diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php index 72af7c8e..39dd417a 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySqliDriver.php @@ -203,17 +203,17 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver /** * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. - * @return int|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { - return mysqli_affected_rows($this->connection) === -1 ? FALSE : mysqli_affected_rows($this->connection); + return mysqli_affected_rows($this->connection) === -1 ? NULL : mysqli_affected_rows($this->connection); } /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { @@ -432,7 +432,7 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/OdbcDriver.php index 10cbcc66..f08294ea 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -34,8 +34,8 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** @var bool */ private $autoFree = TRUE; - /** @var int|FALSE Affected rows */ - private $affectedRows = FALSE; + /** @var int|NULL Affected rows */ + private $affectedRows; /** @var int Cursor */ private $row = 0; @@ -100,14 +100,14 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function query($sql) { - $this->affectedRows = FALSE; + $this->affectedRows = NULL; $res = @odbc_exec($this->connection, $sql); // intentionally @ if ($res === FALSE) { throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection), 0, $sql); } elseif (is_resource($res)) { - $this->affectedRows = odbc_num_rows($res); + $this->affectedRows = Dibi\Helpers::false2Null(odbc_num_rows($res)); return $this->createResultDriver($res); } return NULL; @@ -116,7 +116,7 @@ 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|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { @@ -126,7 +126,7 @@ 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|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { @@ -363,16 +363,16 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { if ($assoc) { - return odbc_fetch_array($this->resultSet, ++$this->row); + return Dibi\Helpers::false2Null(odbc_fetch_array($this->resultSet, ++$this->row)); } else { $set = $this->resultSet; if (!odbc_fetch_row($set, ++$this->row)) { - return FALSE; + return NULL; } $count = odbc_num_fields($set); $cols = []; diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OracleDriver.php index 319cb327..3c489c15 100644 --- a/src/Dibi/Drivers/OracleDriver.php +++ b/src/Dibi/Drivers/OracleDriver.php @@ -43,8 +43,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** @var string Date and datetime format */ private $fmtDate, $fmtDateTime; - /** @var int|FALSE Number of affected rows */ - private $affectedRows = FALSE; + /** @var int|NULL Number of affected rows */ + private $affectedRows; /** @@ -109,7 +109,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function query($sql) { - $this->affectedRows = FALSE; + $this->affectedRows = NULL; $res = oci_parse($this->connection, $sql); if ($res) { @oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT); @@ -118,7 +118,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector throw self::createException($err['message'], $err['code'], $sql); } elseif (is_resource($res)) { - $this->affectedRows = oci_num_rows($res); + $this->affectedRows = Dibi\Helpers::false2Null(oci_num_rows($res)); return $this->createResultDriver($res); } } else { @@ -151,7 +151,7 @@ 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|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { @@ -161,12 +161,12 @@ 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|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { $row = $this->query("SELECT $sequence.CURRVAL AS ID FROM DUAL")->fetch(TRUE); - return isset($row['ID']) ? (int) $row['ID'] : FALSE; + return isset($row['ID']) ? (int) $row['ID'] : NULL; } @@ -396,11 +396,11 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { - return oci_fetch_array($this->resultSet, ($assoc ? OCI_ASSOC : OCI_NUM) | OCI_RETURN_NULLS); + return Dibi\Helpers::false2Null(oci_fetch_array($this->resultSet, ($assoc ? OCI_ASSOC : OCI_NUM) | OCI_RETURN_NULLS)); } diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index 5ebb130a..9c719bd4 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -8,6 +8,7 @@ namespace Dibi\Drivers; use Dibi; +use Dibi\Helpers; use PDO; @@ -33,8 +34,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver /** @var \PDOStatement|NULL Resultset resource */ private $resultSet; - /** @var int|FALSE Affected rows */ - private $affectedRows = FALSE; + /** @var int|NULL Affected rows */ + private $affectedRows; /** @var string */ private $driverName; @@ -63,7 +64,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver { $foo = &$config['dsn']; $foo = &$config['options']; - Dibi\Helpers::alias($config, 'resource', 'pdo'); + Helpers::alias($config, 'resource', 'pdo'); if ($config['resource'] instanceof PDO) { $this->connection = $config['resource']; @@ -106,11 +107,11 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver // must detect if SQL returns result set or num of affected rows $cmd = strtoupper(substr(ltrim($sql), 0, 6)); static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1]; - $this->affectedRows = FALSE; + $this->affectedRows = NULL; if (isset($list[$cmd])) { - $this->affectedRows = $this->connection->exec($sql); - if ($this->affectedRows !== FALSE) { + $this->affectedRows = Helpers::false2Null($this->connection->exec($sql)); + if ($this->affectedRows !== NULL) { return NULL; } } else { @@ -143,7 +144,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver /** * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. - * @return int|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { @@ -153,11 +154,11 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { - return $this->connection->lastInsertId(); + return Helpers::false2Null($this->connection->lastInsertId()); } @@ -499,11 +500,11 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { - return $this->resultSet->fetch($assoc ? PDO::FETCH_ASSOC : PDO::FETCH_NUM); + return Helpers::false2Null($this->resultSet->fetch($assoc ? PDO::FETCH_ASSOC : PDO::FETCH_NUM)); } diff --git a/src/Dibi/Drivers/PostgreDriver.php b/src/Dibi/Drivers/PostgreDriver.php index a07e866c..6e7bafd1 100644 --- a/src/Dibi/Drivers/PostgreDriver.php +++ b/src/Dibi/Drivers/PostgreDriver.php @@ -8,6 +8,7 @@ namespace Dibi\Drivers; use Dibi; +use Dibi\Helpers; /** @@ -35,8 +36,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** @var bool */ private $autoFree = TRUE; - /** @var int|FALSE Affected rows */ - private $affectedRows = FALSE; + /** @var int|NULL Affected rows */ + private $affectedRows; /** @@ -69,8 +70,8 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector $string = $config['string']; } else { $string = ''; - Dibi\Helpers::alias($config, 'user', 'username'); - Dibi\Helpers::alias($config, 'dbname', 'database'); + Helpers::alias($config, 'user', 'username'); + Helpers::alias($config, 'dbname', 'database'); foreach (['host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'] as $key) { if (isset($config[$key])) { $string .= $key . '=' . $config[$key] . ' '; @@ -133,14 +134,14 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function query($sql) { - $this->affectedRows = FALSE; + $this->affectedRows = NULL; $res = @pg_query($this->connection, $sql); // intentionally @ if ($res === FALSE) { throw self::createException(pg_last_error($this->connection), NULL, $sql); } elseif (is_resource($res)) { - $this->affectedRows = pg_affected_rows($res); + $this->affectedRows = Helpers::false2Null(pg_affected_rows($res)); if (pg_num_fields($res)) { return $this->createResultDriver($res); } @@ -179,7 +180,7 @@ 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|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { @@ -189,7 +190,7 @@ 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|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { @@ -201,11 +202,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } if (!$res) { - return FALSE; + return NULL; } $row = $res->fetch(FALSE); - return is_array($row) ? $row[0] : FALSE; + return is_array($row) ? $row[0] : NULL; } @@ -438,11 +439,11 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { - return pg_fetch_array($this->resultSet, NULL, $assoc ? PGSQL_ASSOC : PGSQL_NUM); + return Helpers::false2Null(pg_fetch_array($this->resultSet, NULL, $assoc ? PGSQL_ASSOC : PGSQL_NUM)); } diff --git a/src/Dibi/Drivers/Sqlite3Driver.php b/src/Dibi/Drivers/Sqlite3Driver.php index 083fc99b..3ecff9ba 100644 --- a/src/Dibi/Drivers/Sqlite3Driver.php +++ b/src/Dibi/Drivers/Sqlite3Driver.php @@ -154,7 +154,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver /** * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. - * @return int|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { @@ -164,7 +164,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { @@ -381,11 +381,14 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { $row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM); + if (!$row) { + return NULL; + } $charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT'; if ($row && ($assoc || $charset)) { $tmp = []; diff --git a/src/Dibi/Drivers/SqlsrvDriver.php b/src/Dibi/Drivers/SqlsrvDriver.php index 96847d99..2fa74bd8 100644 --- a/src/Dibi/Drivers/SqlsrvDriver.php +++ b/src/Dibi/Drivers/SqlsrvDriver.php @@ -38,8 +38,8 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver /** @var bool */ private $autoFree = TRUE; - /** @var int|FALSE Affected rows */ - private $affectedRows = FALSE; + /** @var int|NULL Affected rows */ + private $affectedRows; /** @var string */ private $version = ''; @@ -109,7 +109,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver */ public function query($sql) { - $this->affectedRows = FALSE; + $this->affectedRows = NULL; $res = sqlsrv_query($this->connection, $sql); if ($res === FALSE) { @@ -117,7 +117,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver throw new Dibi\DriverException($info[0]['message'], $info[0]['code'], $sql); } elseif (is_resource($res)) { - $this->affectedRows = sqlsrv_rows_affected($res); + $this->affectedRows = Helpers::false2Null(sqlsrv_rows_affected($res)); return $this->createResultDriver($res); } return NULL; @@ -126,7 +126,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver /** * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. - * @return int|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ public function getAffectedRows() { @@ -136,7 +136,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ public function getInsertId($sequence) { @@ -145,7 +145,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver $row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC); return $row[0]; } - return FALSE; + return NULL; } @@ -369,7 +369,7 @@ 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 array on success, nonarray if no next record + * @return array|NULL array on success, NULL if no next record */ public function fetch($assoc) { diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index ad4fcd93..0974dff3 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -319,7 +319,7 @@ class Fluent implements IDataSource /** * Generates, executes SQL query and fetches the single row. - * @return Row|FALSE + * @return Row|NULL */ public function fetch() { @@ -333,7 +333,7 @@ class Fluent implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, FALSE if no next record + * @return mixed value on success, NULL if no next record */ public function fetchSingle() { diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index caa10274..59db2ace 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -282,4 +282,13 @@ class Helpers return $count; } + + /** + * @internal + */ + public static function false2Null($val) + { + return $val === FALSE ? NULL : $val; + } + } diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index 48606938..f954a622 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -174,20 +174,20 @@ 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|FALSE + * @return Row|NULL */ final public function fetch() { $row = $this->getResultDriver()->fetch(TRUE); - if (!is_array($row)) { - return FALSE; + if ($row === NULL) { + return NULL; } $this->fetched = TRUE; $this->normalize($row); if ($this->rowFactory) { return ($this->rowFactory)($row); } elseif ($this->rowClass) { - $row = new $this->rowClass($row); + return new $this->rowClass($row); } return $row; } @@ -195,13 +195,13 @@ class Result implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, FALSE if no next record + * @return mixed value on success, NULL if no next record */ final public function fetchSingle() { $row = $this->getResultDriver()->fetch(TRUE); - if (!is_array($row)) { - return FALSE; + if ($row === NULL) { + return NULL; } $this->fetched = TRUE; $this->normalize($row); diff --git a/src/Dibi/dibi.php b/src/Dibi/dibi.php index 82d16094..d5615b33 100644 --- a/src/Dibi/dibi.php +++ b/src/Dibi/dibi.php @@ -182,7 +182,7 @@ class dibi /** * Executes SQL query and fetch result - Monostate for Dibi\Connection::query() & fetch(). * @param mixed one or more arguments - * @return Dibi\Row + * @return Dibi\Row|NULL * @throws Dibi\Exception */ public static function fetch(...$args) diff --git a/src/Dibi/interfaces.php b/src/Dibi/interfaces.php index 99318027..9119ebbd 100644 --- a/src/Dibi/interfaces.php +++ b/src/Dibi/interfaces.php @@ -49,13 +49,13 @@ interface Driver /** * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. - * @return int|FALSE number of rows or FALSE on error + * @return int|NULL number of rows or NULL on error */ function getAffectedRows(); /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * @return int|FALSE int on success or FALSE on failure + * @return int|NULL int on success or NULL on failure */ function getInsertId($sequence); @@ -166,16 +166,16 @@ interface ResultDriver /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @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 */ function seek($row); /** * 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 array on success, nonarray if no next record + * @param bool TRUE for associative array, FALSE for numeric + * @return array|NULL array on success, NULL if no next record * @internal */ function fetch($type); diff --git a/tests/dibi/Fluent.fetch.limit.mssql.phpt b/tests/dibi/Fluent.fetch.limit.mssql.phpt index 0adfff44..f75d6a81 100644 --- a/tests/dibi/Fluent.fetch.limit.mssql.phpt +++ b/tests/dibi/Fluent.fetch.limit.mssql.phpt @@ -25,7 +25,7 @@ class MockDriver extends Dibi\Drivers\SqlsrvDriver function fetch($assoc) { - return FALSE; + return NULL; } }