to implement the " ON DUPLICATE KEY UPDATE" i add a $duplicate and these lines in class/model/write.php insert function:
le="color: #000000"><?php public function insertUpdate(&$object, $duplicate = array(), $force = true) { $handler = $this->loadHandler('write'); if (!$object->isDirty()) { trigger_error("Data entry is not inserted - the object '" . get_class($object) . "' is not dirty", E_USER_NOTICE); return $object->getVar($this->keyName); } if (!$handler->cleanVars($object)) { trigger_error("Insert failed in method 'cleanVars' of object '" . get_class($object) . "'", E_USER_WARNING); return $object->getVar($this->keyName); } $queryFunc = empty($force) ? "query" : "queryF"; if ($object->isNew()) { $sql = "INSERT INTO {$this->table}"; if (!empty($object->cleanVars)) { $keys = array_keys($object->cleanVars); $vals = array_values($object->cleanVars); $sql .= " (" . implode(", ", $keys) . ") VALUES (" . implode(",", $vals) . ")"; } else { trigger_error("Data entry is not inserted - no variable is changed in object of '" . get_class($object) . "'", E_USER_NOTICE); return $object->getVar($this->keyName); } // START ON DUPLICATE KEY UPDATE if(!empty($duplicate)) { $sql .= " ON DUPLICATE KEY UPDATE"; $keys = array(); foreach($duplicate as $keyD=>$valD) { $keys[] = " {$keyD} = {$valD} "; } $sql .= implode(", ", $keys); } // END ON DUPLICATE KEY UPDATE if (!$result = $this->db->{$queryFunc}($sql)) { return false; } if (!$object->getVar($this->keyName) && $object_id = $this->db->getInsertId()) { $object->assignVar($this->keyName, $object_id); } } else if (!empty($object->cleanVars)) { $keys = array(); foreach ($object->cleanVars as $k => $v) { $keys[] = " `{$k}` = {$v}"; } $sql = "UPDATE `" . $this->table . "` SET " . implode(",", $keys) . " WHERE `" . $this->keyName . "` = " . $this->db->quote($object->getVar($this->keyName)); if (!$result = $this->db->{$queryFunc}($sql)) { return false; } } return $object->getVar($this->keyName); }
then i can use it like this:
le="color: #000000"><?php $ret = $this->userlog->getHandler('stats')->insertUpdate($statsObj, array("stats_value"=>(empty($increment) ? $value : "stats_value + {$value}"), "time_update"=>time()));
and the query is like this: for example for browser = Chrome 26.0
le="color: #000000"><?php 0.000328 - INSERT INTO mod_userlog_stats (stats_type, stats_link, stats_value, stats_period, time_update) VALUES ('browser','Chrome 26.0',1,0,1367673147) ON DUPLICATE KEY UPDATE stats_value = stats_value + 1 , time_update = 1367673147
is this good enough and
most efficient query for increment? I cannot see any functionality in Core for increments like hits = hits + 1
@redheadedrod:
The logger is good enough. I also think it is good to have an option to show/hide prefix in the tables.
then it is up to the core developers how to implement that.