예제 #1
0
 /**
  * Add ON DUPLICATE KEY UPDATE to an INSERT query.
  * 
  * @param mixed $column      Column name, array(column, ...) or array('column' => expression, ...)
  * @param mixed $expression  Expression or value  
  * @param int   $flags       Query::SET_VALUE, Query::SET_EXPRESSION (default) + Query::REPLACE, Query::PREPEND or Query::APPEND (default) + Query::BACKQUOTE_%
  * @return Query  $this
  */
 public function onDuplicateKeyUpdate($column = true, $expression = null, $flags = 0)
 {
     if (is_array($column)) {
         foreach ($column as $key => &$val) {
             if (is_int($key)) {
                 $val = QuerySplitter::backquote($val, $flags & ~self::_BACKQUOTE_OPTIONS | self::BACKQUOTE_STRICT);
                 $val .= " = VALUES({$val})";
             } else {
                 $val = QuerySplitter::backquote($key, $flags & ~self::_BACKQUOTE_OPTIONS | self::BACKQUOTE_STRICT) . ' = ' . ($flags & self::SET_VALUE ? QuerySplitter::quote($val) : QuerySplitter::backquote($val, $flags));
             }
         }
         $column = join(', ', $column);
     } elseif ($column !== true) {
         $column = QuerySplitter::backquote($column, $flags & ~self::_BACKQUOTE_OPTIONS | self::BACKQUOTE_STRICT);
         if (!isset($expression)) {
             $column .= " = VALUES({$column})";
         } elseif ($flags & self::SET_VALUE) {
             $column .= ' = ' . QuerySplitter::quote($value, 'DEFAULT');
         } else {
             $column .= ' = ' . QuerySplitter::mapIdentifiers($value, $flags);
         }
     }
     $this->setPart('on duplicate key update', $column, $flags);
     return $this;
 }