Ticket #1195: RawSql_p1.patch

File RawSql_p1.patch, 1.4 KB (added by stefan, 6 months ago)
  • RawSql.php

     
    7272            $this->_parseSelectFields($queryPart); 
    7373            return $this; 
    7474        } 
    75         if ( ! isset($this->parts[$queryPartName])) { 
     75        if ( ! isset($this->_sqlParts[$queryPartName])) { 
    7676            $this->_sqlParts[$queryPartName] = array(); 
    7777        } 
    7878         
     
    220220            } 
    221221        } 
    222222         
     223        $q = 'SELECT '; 
     224        if($this->_sqlParts['distinct'] == true) $q .= 'DISTINCT '; 
     225 
    223226        // first add the fields of the root component 
    224227        reset($this->_queryComponents); 
    225228        $componentAlias = key($this->_queryComponents); 
    226  
    227         $q = 'SELECT ' . implode(', ', $select[$componentAlias]); 
     229        $q .= implode(', ', $select[$componentAlias]); 
    228230        unset($select[$componentAlias]); 
    229231 
    230232        foreach ($select as $component => $fields) { 
     
    237239        if ( ! empty($string)) { 
    238240            $this->_sqlParts['where'][] = $string; 
    239241        } 
    240         $copy = $this->_sqlParts; 
    241         unset($copy['select']); 
    242242 
    243243        $q .= ( ! empty($this->_sqlParts['from']))?    ' FROM '     . implode(' ', $this->_sqlParts['from']) : ''; 
    244244        $q .= ( ! empty($this->_sqlParts['where']))?   ' WHERE '    . implode(' AND ', $this->_sqlParts['where']) : '';