From ec16e890e899c44c517bd16ce769e53811debdba Mon Sep 17 00:00:00 2001 From: aterekhov Date: Sun, 28 Feb 2010 22:09:51 +0000 Subject: [PATCH] $this->table() now had parameter for auto-escaping #0 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@118 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- model/Model.php | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/model/Model.php b/model/Model.php index 5dfe6ae..95ec672 100644 --- a/model/Model.php +++ b/model/Model.php @@ -1,4 +1,5 @@ db = Db::connect($this->connection); } - + /** * @return int */ public function getInsertId() { - return $this->db->getInsertId($this->table(), $this->key); + return $this->db->getInsertId($this->table(false), $this->key); } - + /** * @param string $ident * @return string Quoted identifier. @@ -50,7 +51,7 @@ abstract class Model { return $this->db->quoteIdentifier($ident); } - + /** * @param mixed $value * @return string Quoted value. @@ -59,18 +60,17 @@ abstract class Model { return $this->db->quote($value); } - + /** * @param int $id * @return object */ public function get($id) { - $sql = 'SELECT * FROM ' . $this->identify($this->table()) - . ' WHERE ' . $this->identify($this->key) . '=' . (int) $id; + $sql = 'SELECT * FROM ' . $this->table() . ' WHERE ' . $this->identify($this->key) . '=' . (int) $id; return $this->db->query($sql)->fetch(); } - + /** * @param array $data * @return int Affect row or id of inserted field. @@ -87,19 +87,19 @@ abstract class Model } return $result; } - + /** * @param array $data * @return int Id of inserted row */ public function insert($data) { - if (! $this->db->insert($this->table(), $data)) { + if (!$this->db->insert($this->table(false), $data)) { return false; } return $this->getInsertId(); } - + /** * @param array $data * @param mixed $where @@ -107,9 +107,9 @@ abstract class Model */ public function update($data, $where) { - return $this->db->update($this->table(), $data, $where); + return $this->db->update($this->table(false), $data, $where); } - + /** * @param mixed $where * @return int Number of affected rows @@ -119,17 +119,18 @@ abstract class Model if (is_int($where)) { $where = $this->identify($this->key) . '=' . (int) $where; } - return $this->db->delete($this->table(), $where); + return $this->db->delete($this->table(false), $where); } - + /** + * @param bool $autoescape * @return string */ - public function table() + public function table($autoescape = true) { - if (! $this->table) { + if (!$this->table) { $this->table = substr(strtolower(get_class($this)), 0, -5/*strlen('Model')*/); } - return $this->table; + return $identify ? $this->identify($this->table) : $this->table; } }