From 32ed383326ea329f65060e9b2e260e4448d5dab1 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 5 Feb 2009 02:13:15 +0000 Subject: [PATCH] - query returns DibiResult or number of affected rows now --- dibi/dibi.php | 4 ++-- dibi/libs/DibiConnection.php | 6 ++++-- dibi/libs/DibiFluent.php | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dibi/dibi.php b/dibi/dibi.php index c39ba2af..6211fe06 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -264,7 +264,7 @@ class dibi /** * Generates and executes SQL query - Monostate for DibiConnection::query(). * @param array|mixed one or more arguments - * @return DibiResult|NULL result set object (if any) + * @return DibiResult|int result set object (if any) * @throws DibiException */ public static function query($args) @@ -278,7 +278,7 @@ class dibi /** * Executes the SQL query - Monostate for DibiConnection::nativeQuery(). * @param string SQL statement. - * @return DibiResult|NULL result set object (if any) + * @return DibiResult|int result set object (if any) */ public static function nativeQuery($sql) { diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index c0fe57c4..6572a3d2 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -235,7 +235,7 @@ class DibiConnection extends DibiObject /** * Generates (translates) and executes SQL query. * @param array|mixed one or more arguments - * @return DibiResult|NULL result set object (if any) + * @return DibiResult|int result set object (if any) * @throws DibiException */ final public function query($args) @@ -292,7 +292,7 @@ class DibiConnection extends DibiObject /** * Executes the SQL query. * @param string SQL statement. - * @return DibiResult|NULL result set object (if any) + * @return DibiResult|int result set object (if any) * @throws DibiException */ final public function nativeQuery($sql) @@ -318,6 +318,8 @@ class DibiConnection extends DibiObject if ($res = $this->driver->query($sql)) { // intentionally = $res = new DibiResult($res, $this->config); + } else { + $res = $this->driver->affectedRows(); } $time += microtime(TRUE); diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index 77297505..8259986b 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -240,12 +240,14 @@ class DibiFluent extends DibiObject implements Countable, IteratorAggregate /** * Generates and executes SQL query. - * @return DibiResult|NULL result set object (if any) + * @param mixed what to return? + * @return DibiResult|int result set object (if any) * @throws DibiException */ - public function execute() + public function execute($return = NULL) { - return $this->connection->query($this->_export()); + $res = $this->connection->query($this->_export()); + return $return === dibi::IDENTIFIER ? $this->connection->insertId() : $res; }