Browse Source

reverted #1598 and added a test for it

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
795c74100d
  1. 2
      framework/yii/db/Query.php
  2. 11
      tests/unit/framework/db/QueryTest.php

2
framework/yii/db/Query.php

@ -148,7 +148,7 @@ class Query extends Component implements QueryInterface
* Executes the query and returns a single row of result. * Executes the query and returns a single row of result.
* @param Connection $db the database connection used to generate the SQL statement. * @param Connection $db the database connection used to generate the SQL statement.
* If this parameter is not given, the `db` application component will be used. * If this parameter is not given, the `db` application component will be used.
* @return array|boolean the first row (in terms of an array) of the query result. Null is returned if the query * @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query
* results in nothing. * results in nothing.
*/ */
public function one($db = null) public function one($db = null)

11
tests/unit/framework/db/QueryTest.php

@ -112,4 +112,15 @@ class QueryTest extends DatabaseTestCase
public function testUnion() public function testUnion()
{ {
} }
public function testOne()
{
$db = $this->getConnection();
$result = (new Query)->from('tbl_customer')->where(['status' => 2])->one($db);
$this->assertEquals('user3', $result['name']);
$result = (new Query)->from('tbl_customer')->where(['status' => 3])->one($db);
$this->assertFalse($result);
}
} }

Loading…
Cancel
Save