/** * Counts the number of beans of type $type. * This method accepts a second argument to modify the count-query. * A third argument can be used to provide bindings for the SQL snippet. * * @param string $type type of bean we are looking for * @param string $addSQL additional SQL snippet * @param array $bindings parameters to bind to SQL * * @return integer * * @throws SQLException */ public function count($type, $addSQL = '', $bindings = array()) { $type = AQueryWriter::camelsSnake($type); if (count(explode('_', $type)) > 2) { throw new RedException('Invalid type for count.'); } try { return (int) $this->writer->queryRecordCount($type, array(), $addSQL, $bindings); } catch (SQLException $exception) { if (!$this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_NO_SUCH_TABLE, QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN))) { throw $exception; } } return 0; }