From be7deeed610871839ba166a5d4c8237e5cdbe864 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 4 Dec 2007 18:59:48 +0000 Subject: Active Record now supports query criteria for implicitly declared related properties --- framework/Data/Common/TDbCommandBuilder.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'framework/Data/Common') diff --git a/framework/Data/Common/TDbCommandBuilder.php b/framework/Data/Common/TDbCommandBuilder.php index 0029b4c3..f358036c 100644 --- a/framework/Data/Common/TDbCommandBuilder.php +++ b/framework/Data/Common/TDbCommandBuilder.php @@ -159,10 +159,10 @@ class TDbCommandBuilder extends TComponent */ public function createFindCommand($where='1=1', $parameters=array(), $ordering=array(), $limit=-1, $offset=-1) { - if($where===null) - $where='1=1'; $table = $this->getTableInfo()->getTableFullName(); - $sql = "SELECT * FROM {$table} WHERE {$where}"; + $sql = "SELECT * FROM {$table}"; + if(!empty($where)) + $sql .= " WHERE {$where}"; return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset); } @@ -185,10 +185,10 @@ class TDbCommandBuilder extends TComponent */ public function createCountCommand($where='1=1', $parameters=array(),$ordering=array(), $limit=-1, $offset=-1) { - if($where===null) - $where='1=1'; $table = $this->getTableInfo()->getTableFullName(); - $sql = "SELECT COUNT(*) FROM {$table} WHERE {$where}"; + $sql = "SELECT COUNT(*) FROM {$table}"; + if(!empty($where)) + $sql .= " WHERE {$where}"; return $this->applyCriterias($sql, $parameters, $ordering, $limit, $offset); } @@ -204,8 +204,8 @@ class TDbCommandBuilder extends TComponent { $table = $this->getTableInfo()->getTableFullName(); if (!empty($where)) - $where = 'WHERE '.$where; - $command = $this->createCommand("DELETE FROM {$table} ".$where); + $where = ' WHERE '.$where; + $command = $this->createCommand("DELETE FROM {$table}".$where); $this->bindArrayValues($command, $parameters); return $command; } @@ -242,7 +242,10 @@ class TDbCommandBuilder extends TComponent $fields = implode(', ', $this->getColumnBindings($data, true)); else $fields = implode(', ', $this->getColumnBindings($data)); - $command = $this->createCommand("UPDATE {$table} SET {$fields} WHERE {$where}"); + + if (!empty($where)) + $where = ' WHERE '.$where; + $command = $this->createCommand("UPDATE {$table} SET {$fields}".$where); $this->bindArrayValues($command, array_merge($data, $parameters)); return $command; } -- cgit v1.2.3