Skip to content

Commit

Permalink
(Fixes issue 694)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.xue committed Dec 7, 2009
1 parent 4729550 commit 6660fd9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Version 1.0.11 to be released
- Enh #684: Improved Yii::import() to throw exception when set_include_path fails (Qiang)
- Enh #685: Added support for recognizing "Z" in CDateFormatter (Qiang)
- Enh #690: Enhanced the email validator pattern to capture 99% valid email addresses (Qiang)
- Enh #694: CActiveRecord count methods will ignore criterias that are incomatible with COUNT SQL statement (Qiang)
- Enh #697: Relational AR queries now also invoke CActiveRecord::beforeFind() (Qiang)
- Enh #703: Upgraded autocomplete js code to version 1.1.0 (Qiang)
- Enh: Added core message translation in Thai (Peerajak)
Expand Down
1 change: 1 addition & 0 deletions framework/db/ar/CActiveFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ public function count($criteria=null)
$query->selects=array("COUNT(*)");

$query->orders=$query->groups=$query->havings=array();
$query->limit=$query->offset=-1;
$command=$query->createCommand($this->_builder);
return $command->queryScalar();
}
Expand Down
8 changes: 6 additions & 2 deletions framework/db/schema/CDbCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ public function createFindCommand($table,$criteria)
public function createCountCommand($table,$criteria)
{
$this->ensureTable($table);
$criteria->select='COUNT(*)';
return $this->createFindCommand($table,$criteria);
$sql=($criteria->distinct ? 'SELECT DISTINCT':'SELECT')." COUNT(*) FROM {$table->rawName}";
$sql=$this->applyJoin($sql,$criteria->join);
$sql=$this->applyCondition($sql,$criteria->condition);
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$criteria->params);
return $command;
}

/**
Expand Down

0 comments on commit 6660fd9

Please sign in to comment.