code: protected function _duplicate_insert_sql($values, $update)
      {
          $updateStr = array();
          $keyStr    = array();
          $valStr    = array();
  
          $values = $this->trigger('before_create', $values);
          $update = $this->trigger('before_update', $update);
  
          foreach ($values as $key => $val) {
              $keyStr[] = $key;
              $valStr[] = $this->_database->escape($val);
          }
  
          foreach ($update as $key => $val) {
              $updateStr[] = $key . " = '{$val}'";
          }
  
          $sql = "INSERT INTO `" . $this->_database->dbprefix($this->_table) . "` (" . implode(', ', $keyStr) . ") ";
          $sql .= "VALUES (" . implode(', ', $valStr) . ") ";
          $sql .= "ON DUPLICATE KEY UPDATE " . implode(", ", $updateStr);
  
          return $sql;
      }
docs: @param      $values
  @param null $update
  
  @return string