Example #1
0
 /**
  * Compile ORDER BY
  *
  * Escapes identifiers in ORDER BY statements at execution time.
  *
  * Required so that aliases are tracked properly, regardless of wether
  * orderBy() is called prior to from(), join() and prefixTable is added
  * only if needed.
  *
  * @return    string    SQL statement
  */
 protected function compileOrderBy()
 {
     if (is_array($this->QBOrderBy) && count($this->QBOrderBy) > 0) {
         for ($i = 0, $c = count($this->QBOrderBy); $i < $c; $i++) {
             if ($this->QBOrderBy[$i]['escape'] !== false && !$this->isLiteral($this->QBOrderBy[$i]['field'])) {
                 $this->QBOrderBy[$i]['field'] = $this->db->protectIdentifiers($this->QBOrderBy[$i]['field']);
             }
             $this->QBOrderBy[$i] = $this->QBOrderBy[$i]['field'] . $this->QBOrderBy[$i]['direction'];
         }
         return $this->QBOrderBy = "\nORDER BY " . implode(', ', $this->QBOrderBy);
     } elseif (is_string($this->QBOrderBy)) {
         return $this->QBOrderBy;
     }
     return '';
 }