|
|
@ -226,6 +226,22 @@ abstract class SqlModel extends Model |
|
|
|
return new SqlResultProvider($result); |
|
|
|
} |
|
|
|
|
|
|
|
public function count($select, $distinct, $where,$heaving = null, $group_by = null, $sql_expression = null, $sql_expression_params = array(), $cache_key = null) |
|
|
|
{ |
|
|
|
$select = $this->db->selectExpr($select, $distinct); |
|
|
|
$where = $this->db->whereExpr($where); |
|
|
|
$group_by = $this->db->groupByExpr($group_by); |
|
|
|
$result = $this->query( |
|
|
|
'SELECT COUNT(*) as count FROM (' . |
|
|
|
(($sql_expression) ? $sql_expression : ('SELECT ' . $select . ' FROM ' . $this->identify($this->table()))) |
|
|
|
. (($where) ? (' WHERE ' . $where) : '') |
|
|
|
. (($group_by) ? (' GROUP BY ' . $group_by) : '') . ') AS x', |
|
|
|
$sql_expression_params, |
|
|
|
$cache_key |
|
|
|
); |
|
|
|
return new SqlResultProvider($result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param $sql_expression null |
|
|
|
* @param $sql_expression_params array |
|
|
|