| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | { |
| 12 | 12 | /** |
| 13 | 13 | * Returns the number of rows returned by a query |
| 14 | 14 | * |
| 15 | + * @since 4.10.0 Return 0 when no result is null | |
| 15 | 16 | * @since 2.19.0 |
| 16 | 17 | * @param null|string $column |
| 17 | 18 | * |
| 18 | 19 | * @return int |
| @@ -18,9 +19,9 @@ | ||
| 18 | 19 | * @return int |
| 19 | 20 | */ |
| 20 | 21 | public function count($column = null) |
| 21 | 22 | { |
| 22 | - $column = ( ! $column || $column === '*') ? '1' : trim($column); | |
| 23 | + $column = (!$column || $column === '*') ? '1' : trim($column); | |
| 23 | 24 | |
| 24 | 25 | if (empty($this->selects)) { |
| 25 | 26 | $this->selects[] = new RawSQL('SELECT COUNT(%1s) AS count', $column); |
| 26 | 27 | } else { |
| @@ -26,9 +27,10 @@ | ||
| 26 | 27 | } else { |
| 27 | 28 | $this->selects[] = new RawSQL('COUNT(%1s) AS count', $column); |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | - return +$this->get()->count; | |
| 31 | + $result = $this->get(); | |
| 32 | + return is_null($result) ? 0 : +$result->count; | |
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | /** |
| 34 | 36 | * Returns the total sum in a set of values |
| @@ -43,9 +45,8 @@ | ||
| 43 | 45 | $this->selects[] = new RawSQL('SELECT SUM(%1s) AS sum', $column); |
| 44 | 46 | |
| 45 | 47 | return +$this->get()->sum; |
| 46 | 48 | } |
| 47 | - | |
| 48 | 49 | |
| 49 | 50 | /** |
| 50 | 51 | * Get the average value in a set of values |
| 51 | 52 | * |