diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-02 15:44:54 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-02 15:44:54 +0000 |
commit | bfbab2ccde9c13a3e220a5f0cdce88c0dba911e2 (patch) | |
tree | eeb480d8689f6249ee63084d917a1ebce4467db7 /engine/lib/database.php | |
parent | aa9cbc871f7683ae6238dcfaca18e2235d35e83d (diff) | |
download | elgg-bfbab2ccde9c13a3e220a5f0cdce88c0dba911e2.tar.gz elgg-bfbab2ccde9c13a3e220a5f0cdce88c0dba911e2.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* Fixed set ommission
git-svn-id: https://code.elgg.org/elgg/trunk@774 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/database.php')
-rw-r--r-- | engine/lib/database.php | 52 |
1 files changed, 52 insertions, 0 deletions
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 @@ -216,6 +216,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. * @author Marcus Povey @@ -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)) { |