11
redheadedrod
Re: add some needed facilities for module developers in working with xoops database.

So then this is not a problem in 2.6...

Sounds to me that the way to resolve this is to change the logger to display the "prefix has been added more than once" type message and leave it at that.

Personally I have a problem putting in code that hides bugs like this otherwise. I can not see myself ever doing this on purpose. Reminds me too much of another developer that likes to be "wishful" thinking...

You should always fix the bug and not just cover it up.

Not to mention that a work around like this still adds lines of code that has to be read and executed every time you perform a query for something that shouldn't exist in the first place.

As to it being in core... One of the main reasons 2.6 was refactored was because of the conflicting and extra code in place.

I think getting into the mindset of doing this is a bad thing and unless it is for security reasons should not be done. Logging it is fine, covering it over is not IMHO and is against my training and experience.

12
irmtfan
Re: add some needed facilities for module developers in working with xoops database.
  • 2013/5/5 1:49

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


to implement the " ON DUPLICATE KEY UPDATE" i add a $duplicate and these lines in class/model/write.php insert function:
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:
$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
0.000328 INSERT INTO mod_userlog_stats (stats_typestats_linkstats_valuestats_periodtime_updateVALUES ('browser','Chrome 26.0',1,0,1367673147ON DUPLICATE KEY UPDATE stats_value stats_value 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.

13
redheadedrod
Re: add some needed facilities for module developers in working with xoops database.

@irmtfan:
Sorry, I was still refering to the prefix stuff.

I haven't really looked at the SQL stuff yet since I have been dealing with my homework. I am on track to be done by Tuesday so I can start looking back at this stuff and look at what else we can add to the code before I finish it and clean it up.

Login

Who's Online

197 user(s) are online (108 user(s) are browsing Support Forums)


Members: 0


Guests: 197


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits