summaryrefslogtreecommitdiff
path: root/framework/Data/Common/TDbCommandBuilder.php
diff options
context:
space:
mode:
authorxue <>2007-12-04 18:59:48 +0000
committerxue <>2007-12-04 18:59:48 +0000
commitbe7deeed610871839ba166a5d4c8237e5cdbe864 (patch)
tree1d0f0f6b51848d0c173beacf45bf8ee8b455d7e7 /framework/Data/Common/TDbCommandBuilder.php
parent021780a79c2adb46438b3e350bfc7e8ca955cbcd (diff)
Active Record now supports query criteria for implicitly declared related properties
Diffstat (limited to 'framework/Data/Common/TDbCommandBuilder.php')
-rw-r--r--framework/Data/Common/TDbCommandBuilder.php21
1 files changed, 12 insertions, 9 deletions
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;
}