diff --git a/dibi/dibi.php b/dibi/dibi.php index 25f84799..081dba46 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -370,27 +370,52 @@ class dibi /** * Gets the number of affected rows. - * Monostate for DibiConnection::affectedRows() + * Monostate for DibiConnection::getAffectedRows() + * @return int number of rows + * @throws DibiException + */ + public static function getAffectedRows() + { + return self::getConnection()->getAffectedRows(); + } + + + + /** + * Gets the number of affected rows. Alias for getAffectedRows(). * @return int number of rows * @throws DibiException */ public static function affectedRows() { - return self::getConnection()->affectedRows(); + return self::getConnection()->getAffectedRows(); } /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. - * Monostate for DibiConnection::insertId() + * Monostate for DibiConnection::getInsertId() + * @param string optional sequence name + * @return int + * @throws DibiException + */ + public static function getInsertId($sequence=NULL) + { + return self::getConnection()->getInsertId($sequence); + } + + + + /** + * Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId(). * @param string optional sequence name * @return int * @throws DibiException */ public static function insertId($sequence=NULL) { - return self::getConnection()->insertId($sequence); + return self::getConnection()->getInsertId($sequence); } diff --git a/dibi/drivers/mssql.php b/dibi/drivers/mssql.php index 3aa9e19e..c6cb30a2 100644 --- a/dibi/drivers/mssql.php +++ b/dibi/drivers/mssql.php @@ -121,7 +121,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return mssql_rows_affected($this->connection); } @@ -132,7 +132,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { $res = mssql_query('SELECT @@IDENTITY', $this->connection); if (is_resource($res)) { @@ -276,7 +276,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { return mssql_num_rows($this->resultSet); } @@ -300,7 +300,6 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver * 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 - * @throws DibiException */ public function seek($row) { diff --git a/dibi/drivers/mssql2005.php b/dibi/drivers/mssql2005.php index 7ee422d5..c3713ef1 100644 --- a/dibi/drivers/mssql2005.php +++ b/dibi/drivers/mssql2005.php @@ -121,7 +121,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return sqlsrv_rows_affected($this->resultSet); } @@ -132,7 +132,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { $res = sqlsrv_query($this->connection, 'SELECT @@IDENTITY'); if (is_resource($res)) { @@ -276,9 +276,9 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { - throw new DibiDriverException('Row count is not available for unbuffered queries.'); + throw new NotSupportedException('Row count is not available for unbuffered queries.'); } @@ -306,11 +306,10 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver * 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 - * @throws DibiException */ public function seek($row) { - throw new DibiDriverException('Cannot seek an unbuffered result set.'); + throw new NotSupportedException('Cannot seek an unbuffered result set.'); } diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php index f98484f3..65e0709d 100644 --- a/dibi/drivers/mysql.php +++ b/dibi/drivers/mysql.php @@ -198,7 +198,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return mysql_affected_rows($this->connection); } @@ -209,7 +209,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { return mysql_insert_id($this->connection); } @@ -345,7 +345,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { if (!$this->buffered) { throw new DibiDriverException('Row count is not available for unbuffered queries.'); diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php index 078aed5b..b0fa1043 100644 --- a/dibi/drivers/mysqli.php +++ b/dibi/drivers/mysqli.php @@ -182,7 +182,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return mysqli_affected_rows($this->connection); } @@ -193,7 +193,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { return mysqli_insert_id($this->connection); } @@ -328,7 +328,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { if (!$this->buffered) { throw new DibiDriverException('Row count is not available for unbuffered queries.'); diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index 9341dcf7..d9dcef68 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -125,7 +125,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return odbc_num_rows($this->resultSet); } @@ -136,7 +136,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { throw new NotSupportedException('ODBC does not support autoincrementing.'); } @@ -280,7 +280,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { // will return -1 with many drivers :-( return odbc_num_rows($this->resultSet); @@ -314,7 +314,6 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver * 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 - * @throws DibiException */ public function seek($row) { diff --git a/dibi/drivers/oracle.php b/dibi/drivers/oracle.php index 1a18dd07..8b7c5d26 100644 --- a/dibi/drivers/oracle.php +++ b/dibi/drivers/oracle.php @@ -126,7 +126,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { throw new NotImplementedException; } @@ -137,7 +137,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { throw new NotSupportedException('Oracle does not support autoincrementing.'); } @@ -148,7 +148,6 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver * Begins a transaction (if supported). * @param string optinal savepoint name * @return void - * @throws DibiDriverException */ public function begin($savepoint = NULL) { @@ -278,9 +277,9 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { - throw new DibiDriverException('Row count is not available for unbuffered queries.'); + throw new NotSupportedException('Row count is not available for unbuffered queries.'); } @@ -302,7 +301,6 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver * 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 - * @throws DibiException */ public function seek($row) { diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index 7f6a51dd..16d02b66 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -142,7 +142,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return $this->affectedRows; } @@ -153,7 +153,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { return $this->connection->lastInsertId(); } @@ -347,9 +347,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { - throw new DibiDriverException('Row count is not available for unbuffered queries.'); + throw new NotSupportedException('Row count is not available for unbuffered queries.'); } @@ -371,11 +371,10 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver * 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 - * @throws DibiException */ public function seek($row) { - throw new DibiDriverException('Cannot seek an unbuffered result set.'); + throw new NotSupportedException('Cannot seek an unbuffered result set.'); } diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php index 4659563b..a7a2ddfb 100644 --- a/dibi/drivers/postgre.php +++ b/dibi/drivers/postgre.php @@ -147,7 +147,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return pg_affected_rows($this->resultSet); } @@ -158,7 +158,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { if ($sequence === NULL) { // PostgreSQL 8.1 is needed @@ -326,7 +326,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { return pg_num_rows($this->resultSet); } @@ -350,7 +350,6 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver * 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 - * @throws DibiException */ public function seek($row) { @@ -417,7 +416,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver { $version = pg_version($this->connection); if ($version['server'] < 8) { - throw new NotSupportedException('Reflection requires PostgreSQL 8.'); + throw new DibiDriverException('Reflection requires PostgreSQL 8.'); } $this->query(" diff --git a/dibi/drivers/sqlite.php b/dibi/drivers/sqlite.php index a78e577e..cbe7006b 100644 --- a/dibi/drivers/sqlite.php +++ b/dibi/drivers/sqlite.php @@ -145,7 +145,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - public function affectedRows() + public function getAffectedRows() { return sqlite_changes($this->connection); } @@ -156,7 +156,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - public function insertId($sequence) + public function getInsertId($sequence) { return sqlite_last_insert_rowid($this->connection); } @@ -287,7 +287,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver * Returns the number of rows in a result set. * @return int */ - public function rowCount() + public function getRowCount() { if (!$this->buffered) { throw new DibiDriverException('Row count is not available for unbuffered queries.'); diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index 931446b9..3a4930b3 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -338,7 +338,7 @@ class DibiConnection extends DibiObject if ($res = $this->driver->query($sql)) { // intentionally = $res = new DibiResult($res, $this->config); } else { - $res = $this->driver->affectedRows(); + $res = $this->driver->getAffectedRows(); } $time += microtime(TRUE); @@ -358,30 +358,55 @@ class DibiConnection extends DibiObject * @return int number of rows * @throws DibiException */ - public function affectedRows() + public function getAffectedRows() { - $rows = $this->driver->affectedRows(); + $rows = $this->driver->getAffectedRows(); if (!is_int($rows) || $rows < 0) throw new DibiException('Cannot retrieve number of affected rows.'); return $rows; } + /** + * Gets the number of affected rows. Alias for getAffectedRows(). + * @return int number of rows + * @throws DibiException + */ + public function affectedRows() + { + return $this->getAffectedRows(); + } + + + /** * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @param string optional sequence name * @return int * @throws DibiException */ - public function insertId($sequence = NULL) + public function getInsertId($sequence = NULL) { - $id = $this->driver->insertId($sequence); + $id = $this->driver->getInsertId($sequence); if ($id < 1) throw new DibiException('Cannot retrieve last generated ID.'); return (int) $id; } + /** + * Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId(). + * @param string optional sequence name + * @return int + * @throws DibiException + */ + public function insertId($sequence = NULL) + { + return $this->getInsertId($sequence); + } + + + /** * Begins a transaction (if supported). * @param string optinal savepoint name diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index ff72940e..69426e0d 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -262,7 +262,7 @@ class DibiFluent extends DibiObject implements IDataSource public function execute($return = NULL) { $res = $this->connection->query($this->_export()); - return $return === dibi::IDENTIFIER ? $this->connection->insertId() : $res; + return $return === dibi::IDENTIFIER ? $this->connection->getInsertId() : $res; } diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 86f24fec..16adcb3d 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -116,9 +116,20 @@ class DibiResult extends DibiObject implements IDataSource * Returns the number of rows in a result set. * @return int */ + final public function getRowCount() + { + return $this->getDriver()->getRowCount(); + } + + + + /** + * Returns the number of rows in a result set. Alias for getRowCount(). + * @return int + */ final public function rowCount() { - return $this->getDriver()->rowCount(); + return $this->getDriver()->getRowCount(); } @@ -602,7 +613,7 @@ class DibiResult extends DibiObject implements IDataSource */ final public function count() { - return $this->rowCount(); + return $this->getRowCount(); } diff --git a/dibi/libs/interfaces.php b/dibi/libs/interfaces.php index ab57163a..0f82031a 100644 --- a/dibi/libs/interfaces.php +++ b/dibi/libs/interfaces.php @@ -147,7 +147,7 @@ interface IDibiDriver * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query. * @return int|FALSE number of rows or FALSE on error */ - function affectedRows(); + function getAffectedRows(); @@ -155,7 +155,7 @@ interface IDibiDriver * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @return int|FALSE int on success or FALSE on failure */ - function insertId($sequence); + function getInsertId($sequence); @@ -242,7 +242,7 @@ interface IDibiDriver * Returns the number of rows in a result set. * @return int */ - function rowCount(); + function getRowCount();