/** * Quotes the field (and table) names within an order by clause with the quote * character suitable for the DB being used * * @param string $orderBy An order by clause that can by parsed by parseFieldList * @return string Usable order by clause with quoted field/table names */ protected function quoteOrderBy($orderBy) { if ($orderBy === '') { return ''; } if ($this->runningNative()) { return $orderBy; } $orderBy = $this->SQLparser->parseFieldList($orderBy); $orderBy = $this->_quoteOrderBy($orderBy); return $this->SQLparser->compileFieldList($orderBy); }
/** * Compiles a "SELECT [output] FROM..:" field list based on input array (made with ->parseFieldList()) * Can also compile field lists for ORDER BY and GROUP BY. * * @param array $selectFields Array of select fields, (made with ->parseFieldList()) * @param boolean $compileComments Whether comments should be compiled * @param boolean $functionMapping Whether function mapping should take place * @return string Select field string * @see parseFieldList() */ public function compileFieldList($selectFields, $compileComments = TRUE, $functionMapping = TRUE) { $output = ''; switch ((string) $this->databaseConnection->handlerCfg[$this->databaseConnection->lastHandlerKey]['type']) { case 'native': $output = parent::compileFieldList($selectFields, $compileComments); break; case 'adodb': // Traverse the selectFields if any: if (is_array($selectFields)) { $outputParts = array(); foreach ($selectFields as $k => $v) { // Detecting type: switch ($v['type']) { case 'function': $outputParts[$k] = $v['function'] . '(' . $v['func_content'] . ')'; break; case 'flow-control': if ($v['flow-control']['type'] === 'CASE') { $outputParts[$k] = $this->compileCaseStatement($v['flow-control'], $functionMapping); } break; case 'field': $outputParts[$k] = ($v['distinct'] ? $v['distinct'] : '') . ($v['table'] ? $v['table'] . '.' : '') . $v['field']; break; } // Alias: if ($v['as']) { $outputParts[$k] .= ' ' . $v['as_keyword'] . ' ' . $v['as']; } // Specifically for ORDER BY and GROUP BY field lists: if ($v['sortDir']) { $outputParts[$k] .= ' ' . $v['sortDir']; } } // TODO: Handle SQL hints in comments according to current DBMS if (FALSE && $selectFields[0]['comments']) { $output = $selectFields[0]['comments'] . ' '; } $output .= implode(', ', $outputParts); } break; } return $output; }