From f03cdf0a47bfb42c839eecf68ff08595e092a52f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 9 Jul 2013 08:01:10 -0400 Subject: [PATCH] renamed Command::queryRow() to queryOne(). --- framework/yii/caching/DbDependency.php | 4 ++-- framework/yii/db/ActiveQuery.php | 2 +- framework/yii/db/Command.php | 4 ++-- framework/yii/db/Query.php | 2 +- framework/yii/db/mysql/QueryBuilder.php | 2 +- framework/yii/db/mysql/Schema.php | 2 +- framework/yii/rbac/DbManager.php | 4 ++-- framework/yii/web/DbSession.php | 2 +- tests/unit/framework/db/CommandTest.php | 16 ++++++++-------- tests/unit/framework/db/mssql/MssqlCommandTest.php | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/framework/yii/caching/DbDependency.php b/framework/yii/caching/DbDependency.php index da6f20b..0b559d7 100644 --- a/framework/yii/caching/DbDependency.php +++ b/framework/yii/caching/DbDependency.php @@ -66,10 +66,10 @@ class DbDependency extends Dependency if ($db->enableQueryCache) { // temporarily disable and re-enable query caching $db->enableQueryCache = false; - $result = $db->createCommand($this->sql, $this->params)->queryRow(); + $result = $db->createCommand($this->sql, $this->params)->queryOne(); $db->enableQueryCache = true; } else { - $result = $db->createCommand($this->sql, $this->params)->queryRow(); + $result = $db->createCommand($this->sql, $this->params)->queryOne(); } return $result; } diff --git a/framework/yii/db/ActiveQuery.php b/framework/yii/db/ActiveQuery.php index 9a2fc0d..e0c40f7 100644 --- a/framework/yii/db/ActiveQuery.php +++ b/framework/yii/db/ActiveQuery.php @@ -123,7 +123,7 @@ class ActiveQuery extends Query public function one($db = null) { $command = $this->createCommand($db); - $row = $command->queryRow(); + $row = $command->queryOne(); if ($row !== false && !$this->asArray) { /** @var $class ActiveRecord */ $class = $this->modelClass; diff --git a/framework/yii/db/Command.php b/framework/yii/db/Command.php index 20eb72a..719f47f 100644 --- a/framework/yii/db/Command.php +++ b/framework/yii/db/Command.php @@ -19,7 +19,7 @@ use yii\caching\Cache; * * To execute a non-query SQL (such as INSERT, DELETE, UPDATE), call [[execute()]]. * To execute a SQL statement that returns result data set (such as SELECT), - * use [[queryAll()]], [[queryRow()]], [[queryColumn()]], [[queryScalar()]], or [[query()]]. + * use [[queryAll()]], [[queryOne()]], [[queryColumn()]], [[queryScalar()]], or [[query()]]. * For example, * * ~~~ @@ -335,7 +335,7 @@ class Command extends \yii\base\Component * results in nothing. * @throws Exception execution failed */ - public function queryRow($fetchMode = null) + public function queryOne($fetchMode = null) { return $this->queryInternal('fetch', $fetchMode); } diff --git a/framework/yii/db/Query.php b/framework/yii/db/Query.php index 0af67a9..74633f7 100644 --- a/framework/yii/db/Query.php +++ b/framework/yii/db/Query.php @@ -166,7 +166,7 @@ class Query extends Component */ public function one($db = null) { - return $this->createCommand($db)->queryRow(); + return $this->createCommand($db)->queryOne(); } /** diff --git a/framework/yii/db/mysql/QueryBuilder.php b/framework/yii/db/mysql/QueryBuilder.php index b4ac996..ae6949a 100644 --- a/framework/yii/db/mysql/QueryBuilder.php +++ b/framework/yii/db/mysql/QueryBuilder.php @@ -50,7 +50,7 @@ class QueryBuilder extends \yii\db\QueryBuilder public function renameColumn($table, $oldName, $newName) { $quotedTable = $this->db->quoteTableName($table); - $row = $this->db->createCommand('SHOW CREATE TABLE ' . $quotedTable)->queryRow(); + $row = $this->db->createCommand('SHOW CREATE TABLE ' . $quotedTable)->queryOne(); if ($row === false) { throw new Exception("Unable to find column '$oldName' in table '$table'."); } diff --git a/framework/yii/db/mysql/Schema.php b/framework/yii/db/mysql/Schema.php index b42ef15..225ef38 100644 --- a/framework/yii/db/mysql/Schema.php +++ b/framework/yii/db/mysql/Schema.php @@ -212,7 +212,7 @@ class Schema extends \yii\db\Schema */ protected function findConstraints($table) { - $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteSimpleTableName($table->name))->queryRow(); + $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteSimpleTableName($table->name))->queryOne(); if (isset($row['Create Table'])) { $sql = $row['Create Table']; } else { diff --git a/framework/yii/rbac/DbManager.php b/framework/yii/rbac/DbManager.php index 8d3bea2..90d301e 100644 --- a/framework/yii/rbac/DbManager.php +++ b/framework/yii/rbac/DbManager.php @@ -303,7 +303,7 @@ class DbManager extends Manager $row = $query->from($this->assignmentTable) ->where(array('user_id' => $userId, 'item_name' => $itemName)) ->createCommand($this->db) - ->queryRow(); + ->queryOne(); if ($row !== false) { if (($data = @unserialize($row['data'])) === false) { $data = null; @@ -479,7 +479,7 @@ class DbManager extends Manager $row = $query->from($this->itemTable) ->where(array('name' => $name)) ->createCommand($this->db) - ->queryRow(); + ->queryOne(); if ($row !== false) { if (($data = @unserialize($row['data'])) === false) { diff --git a/framework/yii/web/DbSession.php b/framework/yii/web/DbSession.php index e81aa7f..30f5ed0 100644 --- a/framework/yii/web/DbSession.php +++ b/framework/yii/web/DbSession.php @@ -111,7 +111,7 @@ class DbSession extends Session $row = $query->from($this->sessionTable) ->where(array('id' => $oldID)) ->createCommand($this->db) - ->queryRow(); + ->queryOne(); if ($row !== false) { if ($deleteOldSession) { $this->db->createCommand() diff --git a/tests/unit/framework/db/CommandTest.php b/tests/unit/framework/db/CommandTest.php index 3bd4f4d..dac5f61 100644 --- a/tests/unit/framework/db/CommandTest.php +++ b/tests/unit/framework/db/CommandTest.php @@ -99,22 +99,22 @@ class CommandTest extends DatabaseTestCase $rows = $db->createCommand('SELECT * FROM tbl_customer WHERE id=10')->queryAll(); $this->assertEquals(array(), $rows); - // queryRow + // queryOne $sql = 'SELECT * FROM tbl_customer ORDER BY id'; - $row = $db->createCommand($sql)->queryRow(); + $row = $db->createCommand($sql)->queryOne(); $this->assertEquals(1, $row['id']); $this->assertEquals('user1', $row['name']); $sql = 'SELECT * FROM tbl_customer ORDER BY id'; $command = $db->createCommand($sql); $command->prepare(); - $row = $command->queryRow(); + $row = $command->queryOne(); $this->assertEquals(1, $row['id']); $this->assertEquals('user1', $row['name']); $sql = 'SELECT * FROM tbl_customer WHERE id=10'; $command = $db->createCommand($sql); - $this->assertFalse($command->queryRow()); + $this->assertFalse($command->queryOne()); // queryColumn $sql = 'SELECT * FROM tbl_customer'; @@ -178,7 +178,7 @@ class CommandTest extends DatabaseTestCase $this->assertEquals(1, $command->execute()); $sql = 'SELECT * FROM tbl_type'; - $row = $db->createCommand($sql)->queryRow(); + $row = $db->createCommand($sql)->queryOne(); $this->assertEquals($intCol, $row['int_col']); $this->assertEquals($charCol, $row['char_col']); $this->assertEquals($floatCol, $row['float_col']); @@ -204,20 +204,20 @@ class CommandTest extends DatabaseTestCase // default: FETCH_ASSOC $sql = 'SELECT * FROM tbl_customer'; $command = $db->createCommand($sql); - $result = $command->queryRow(); + $result = $command->queryOne(); $this->assertTrue(is_array($result) && isset($result['id'])); // FETCH_OBJ, customized via fetchMode property $sql = 'SELECT * FROM tbl_customer'; $command = $db->createCommand($sql); $command->fetchMode = \PDO::FETCH_OBJ; - $result = $command->queryRow(); + $result = $command->queryOne(); $this->assertTrue(is_object($result)); // FETCH_NUM, customized in query method $sql = 'SELECT * FROM tbl_customer'; $command = $db->createCommand($sql); - $result = $command->queryRow(array(), \PDO::FETCH_NUM); + $result = $command->queryOne(array(), \PDO::FETCH_NUM); $this->assertTrue(is_array($result) && isset($result[0])); } diff --git a/tests/unit/framework/db/mssql/MssqlCommandTest.php b/tests/unit/framework/db/mssql/MssqlCommandTest.php index f3c66c1..75447bd 100644 --- a/tests/unit/framework/db/mssql/MssqlCommandTest.php +++ b/tests/unit/framework/db/mssql/MssqlCommandTest.php @@ -63,7 +63,7 @@ class MssqlCommandTest extends CommandTest $this->assertEquals(1, $command->execute()); $sql = 'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM tbl_type'; - $row = $db->createCommand($sql)->queryRow(); + $row = $db->createCommand($sql)->queryOne(); $this->assertEquals($intCol, $row['int_col']); $this->assertEquals($charCol, trim($row['char_col'])); $this->assertEquals($floatCol, $row['float_col']);