From bfbab2ccde9c13a3e220a5f0cdce88c0dba911e2 Mon Sep 17 00:00:00 2001 From: icewing Date: Mon, 2 Jun 2008 15:44:54 +0000 Subject: Marcus Povey * Fixed set ommission git-svn-id: https://code.elgg.org/elgg/trunk@774 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/database.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/database.php b/engine/lib/database.php index c09b07d57..420cb6f4c 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -215,6 +215,38 @@ } } + /** + * @class SetQueryComponent Set query. + * Represents an update set query. + * @author Marcus Povey + */ + class SetQueryComponent extends QueryComponent + { + /** + * Construct a setting query + * + * @param string $table The table to modify + * @param string $field The field to modify + * @param mixed $value The value to set it to + */ + function __construct($table, $field, $value) + { + global $CONFIG; + + $this->table = $CONFIG->dbprefix . sanitise_string($table); + $this->field = sanitise_string($field); + if (is_numeric($value)) + $this->value = (int)$value; + else + $this->value = "'".sanitise_string($value)."'"; + } + + function __toString() + { + return "{$this->table}.{$this->field}={$this->value}"; + } + } + /** * @class WhereQueryComponent * A component of a where query. @@ -417,6 +449,9 @@ /// Join tables private $joins; + /// Set values + private $sets; + /// Where query private $where; @@ -438,6 +473,7 @@ $this->tables = array(); $this->joins = array(); $this->where = array(); + $this->sets = array(); $this->setQueryType(new SelectQueryTypeQueryComponent()); } @@ -454,6 +490,8 @@ public function addJoin(JoinQueryComponent $component) { $this->joins[] = $component; } + public function addSet(SetQueryComponent $component) { $this->sets[] = $component; } + public function setQueryType(QueryTypeQueryComponent $component) { $this->query_type = $component; } public function setOrder(OrderQueryComponent $component) { $this->order = $component; } @@ -513,6 +551,20 @@ } } + // Setting values + if ( + ($this->query_type->query_type == 'update') || + ($this->query_type->query_type == 'insert') + ) + { + $sql .= "set "; + + foreach ($this->sets as $set) + $sql .= "$set, "; + + $sql = trim($sql, ", ") . " "; + } + // Where if (!empty($this->where)) { -- cgit v1.2.3