diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-25 10:24:29 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-25 10:24:29 +0000 |
commit | b91992187d732c07854fd185e201eff84125a636 (patch) | |
tree | b06d734726f5ac274944cb998a7c879fe30e7759 | |
parent | 318591526459e1ac1bb8b0acbbcf4bf9f02f8e88 (diff) |
Updated Kohana to r3845
-rw-r--r-- | kohana/libraries/Database.php | 66 | ||||
-rw-r--r-- | kohana/libraries/ORM.php | 5 |
2 files changed, 70 insertions, 1 deletions
diff --git a/kohana/libraries/Database.php b/kohana/libraries/Database.php index fd1ae3fa..7c484465 100644 --- a/kohana/libraries/Database.php +++ b/kohana/libraries/Database.php @@ -49,6 +49,9 @@ class Database_Core { protected $offset = FALSE; protected $last_query = ''; + // Stack of queries for push/pop + protected $query_history = array(); + /** * Returns a singleton instance of Database. * @@ -910,7 +913,9 @@ class Database_Core { } $values = implode(",", $escaped_values); } - $this->where($this->driver->escape_column($field).' '.($not === TRUE ? 'NOT ' : '').'IN ('.$values.')'); + + $where = $this->driver->escape_column(((strpos($field,'.') !== FALSE) ? $this->config['table_prefix'] : ''). $field).' '.($not === TRUE ? 'NOT ' : '').'IN ('.$values.')'; + $this->where[] = $this->driver->where($where, '', 'AND ', count($this->where), -1); return $this; } @@ -1265,6 +1270,65 @@ class Database_Core { return $this->driver->stmt_prepare($sql, $this->config); } + /** + * Pushes existing query space onto the query stack. Use push + * and pop to prevent queries from clashing before they are + * executed + * + * @return Database_Core This Databaes object + */ + public function push() + { + array_push($this->query_history, array( + $this->select, + $this->from, + $this->join, + $this->where, + $this->orderby, + $this->order, + $this->groupby, + $this->having, + $this->distinct, + $this->limit, + $this->offset + )); + + $this->reset_select(); + + return $this; + } + + /** + * Pops from query stack into the current query space. + * + * @return Database_Core This Databaes object + */ + public function pop() + { + if (count($this->query_history) == 0) + { + // No history + return $this; + } + + list( + $this->select, + $this->from, + $this->join, + $this->where, + $this->orderby, + $this->order, + $this->groupby, + $this->having, + $this->distinct, + $this->limit, + $this->offset + ) = array_pop($this->query_history); + + return $this; + } + + } // End Database Class diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php index 7fe126c9..99a8dc4f 100644 --- a/kohana/libraries/ORM.php +++ b/kohana/libraries/ORM.php @@ -1408,6 +1408,9 @@ class ORM_Core { */ protected function load_relations($table, ORM $model) { + // Save the current query chain (otherwise the next call will clash) + $this->db->push(); + $query = $this->db ->select($model->foreign_key(NULL).' AS id') ->from($table) @@ -1415,6 +1418,8 @@ class ORM_Core { ->get() ->result(TRUE); + $this->db->pop(); + $relations = array(); foreach ($query as $row) { |