Skip to content

Commit

Permalink
Connection::query() and Fluent::execute() returns only resultset, not…
Browse files Browse the repository at this point in the history
… the number of affected rows (BC break)
  • Loading branch information
dg committed May 4, 2018
1 parent 75510a8 commit 8695881
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
13 changes: 3 additions & 10 deletions src/Dibi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,9 @@ final public function getDriver(): Driver
/**
* Generates (translates) and executes SQL query.
* @param mixed ...$args
* @return Result|int|null result set or number of affected rows
* @throws Exception
*/
final public function query(...$args)
final public function query(...$args): ?Result
{
return $this->nativeQuery($this->translateArgs($args));
}
Expand Down Expand Up @@ -257,10 +256,9 @@ protected function translateArgs(array $args): string

/**
* Executes the SQL query.
* @return Result|int|null result set or number of affected rows
* @throws Exception
*/
final public function nativeQuery(string $sql)
final public function nativeQuery(string $sql): ?Result
{
if (!$this->driver) {
$this->connect();
Expand All @@ -278,12 +276,7 @@ final public function nativeQuery(string $sql)
throw $e;
}

if ($res) {
$res = $this->createResultSet($res);
} else {
$res = $this->driver->getAffectedRows();
}

$res = $res ? $this->createResultSet($res) : null;
if ($event) {
$this->onEvent($event->done($res));
}
Expand Down
5 changes: 1 addition & 4 deletions src/Dibi/Fluent.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,7 @@ public function count(): int
}


/**
* @return Result|int
*/
private function query($args)
private function query($args): ?Result
{
$res = $this->connection->query($args);
foreach ($this->setups as $setup) {
Expand Down
4 changes: 2 additions & 2 deletions src/Dibi/dibi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* store connections info.
*
* @method void disconnect()
* @method Dibi\Result|int|null query(...$args)
* @method Dibi\Result|int|null nativeQuery(...$args)
* @method Dibi\Result|null query(...$args)
* @method Dibi\Result|null nativeQuery(...$args)
* @method bool test(...$args)
* @method Dibi\DataSource dataSource(...$args)
* @method Dibi\Row|null fetch(...$args)
Expand Down
3 changes: 1 addition & 2 deletions src/Dibi/interfaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ function getDriver(): Driver;

/**
* Generates (translates) and executes SQL query.
* @return Result|int|null result set or number of affected rows
* @throws Exception
*/
function query(...$args);
function query(...$args): ?Result;

/**
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
Expand Down
3 changes: 2 additions & 1 deletion tests/dibi/Fluent.fetch.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ if (!in_array($config['system'], ['odbc', 'sqlsrv'], true)) {

// affected rows
$res = $conn->update('products', ['title' => 'new'])->execute();
Assert::same(3, $res);
Assert::null($res);
Assert::same(3, $conn->getAffectedRows());

0 comments on commit 8695881

Please sign in to comment.