From cd2caca0ab82cda466c9fe70e2aab472ba190a0a Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 26 Nov 2013 10:17:45 -0600 Subject: [PATCH] Fix several issues commiting data to db orm: Fix detection of statement failure orm: Fix type detection of InstrumentedList::add mysqli: Set object-level character set --- include/class.orm.php | 11 +++++++---- include/mysqli.php | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/class.orm.php b/include/class.orm.php index 4b63be4a4..de47d422e 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -147,7 +147,7 @@ class VerySimpleModel { foreach ($pk as $p) $filter[] = $p.' = '.db_input($this->get($p)); $sql .= ' WHERE '.implode(' AND ', $filter).' LIMIT 1'; - return db_affected_rows(db_query($sql)) == 1; + return db_query($sql) && db_affected_rows() == 1; } function save($refetch=false) { @@ -173,10 +173,8 @@ class VerySimpleModel { $sql .= ' WHERE '.implode(' AND ', $filter); $sql .= ' LIMIT 1'; } - if (db_affected_rows(db_query($sql)) != 1) { + if (!db_query($sql) || db_affected_rows() != 1) throw new Exception(db_error()); - return false; - } if ($this->__new__) { if (count($pk) == 1) $this->ht[$pk[0]] = db_insert_id(); @@ -433,17 +431,22 @@ class FlatArrayIterator extends ModelInstanceIterator { class InstrumentedList extends ModelInstanceIterator { var $key; var $id; + var $model; function __construct($fkey, $queryset=false) { list($model, $this->key, $this->id) = $fkey; if (!$queryset) $queryset = $model::objects()->filter(array($this->key=>$this->id)); parent::__construct($queryset); + $this->model = $model; if (!$this->id) $this->resource = null; } function add($object) { + if (!$object || !$object instanceof $this->model) + throw new Exception('Attempting to add invalid object to list'); + $object->{$this->key} = $this->id; $object->save(); $this->list[] = $object; diff --git a/include/mysqli.php b/include/mysqli.php index 7d765b428..34fa57479 100644 --- a/include/mysqli.php +++ b/include/mysqli.php @@ -60,6 +60,7 @@ function db_connect($host, $user, $passwd, $options = array()) { @$__db->query('SET NAMES "utf8"'); @$__db->query('SET CHARACTER SET "utf8"'); @$__db->query('SET COLLATION_CONNECTION=utf8_general_ci'); + $__db->set_charset('utf8'); @db_set_variable('sql_mode', ''); -- GitLab