summaryrefslogtreecommitdiff
path: root/idiorm.php
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-10-25 13:34:40 +0100
committerJamie Matthews <[email protected]>2010-10-25 13:34:40 +0100
commita51c6886f04d7fec8563f3ffad70b97e3c5b1aed (patch)
tree8e308a67023ed2c45f1ad871e81fbafebcb6a6de /idiorm.php
parentf12ff9e42708caea6ec3d25265d0844a6d803149 (diff)
Convert count method to use select_expr method, remove $_find_type as this is no longer needed
Diffstat (limited to 'idiorm.php')
-rw-r--r--idiorm.php21
1 files changed, 3 insertions, 18 deletions
diff --git a/idiorm.php b/idiorm.php
index b630cc9..86fbd1b 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -44,11 +44,6 @@
// --- CLASS CONSTANTS --- //
// ----------------------- //
- // Find types
- const FIND_ONE = 0;
- const FIND_MANY = 1;
- const COUNT = 2;
-
// Update or insert?
const UPDATE = 0;
const INSERT = 1;
@@ -89,9 +84,6 @@
// The name of the table the current ORM instance is associated with
protected $_table_name;
- // Will be FIND_ONE or FIND_MANY
- protected $_find_type;
-
// Values to be bound to the query
protected $_values = array();
@@ -309,7 +301,6 @@
$this->where($this->_get_id_column_name(), $id);
}
$this->limit(1);
- $this->_find_type = self::FIND_ONE;
$statement = $this->_run();
$result = $statement->fetch(PDO::FETCH_ASSOC);
return $result ? self::for_table($this->_table_name)->use_id_column($this->_instance_id_column)->hydrate($result) : $result;
@@ -322,7 +313,6 @@
* no rows were returned.
*/
public function find_many() {
- $this->_find_type = self::FIND_MANY;
$statement = $this->_run();
$instances = array();
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
@@ -337,7 +327,7 @@
* rows returned.
*/
public function count() {
- $this->_find_type = self::COUNT;
+ $this->select_expr('COUNT(*)', 'count');
$statement = $this->_run();
$result = $statement->fetch(PDO::FETCH_ASSOC);
return isset($result['count']) ? (int) $result['count'] : 0;
@@ -602,13 +592,8 @@
* Build the start of the SELECT statement
*/
protected function _build_select_start() {
- if ($this->_find_type === self::COUNT) {
- $count_column = $this->_quote_identifier('count');
- return "SELECT COUNT(*) AS $count_column FROM " . $this->_quote_identifier($this->_table_name);
- } else {
- $result_columns = join(', ', $this->_result_columns);
- return "SELECT {$result_columns} FROM " . $this->_quote_identifier($this->_table_name);
- }
+ $result_columns = join(', ', $this->_result_columns);
+ return "SELECT {$result_columns} FROM " . $this->_quote_identifier($this->_table_name);
}
/**