Example #1
0
 /**
  * Parses statement source.
  * @return string
  */
 protected function parseSource()
 {
     if (!$this->stmt instanceof Result) {
         return $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER);
     }
     // Simple table
     if ($this->stmt->getTable() !== null) {
         $source = $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER);
     } else {
         $subq = $this->stmt->getSource();
         $alias = $this->escapeValue($subq->getAlias() ? $subq->getAlias() : '_table_', Manager::IDENTIFIER);
         $source = "(\n\t" . implode("\n\t", explode("\n", $subq)) . "\n) {$alias}";
     }
     $source = $this->tryDelimite($source);
     // JOINs
     foreach ($this->stmt->getJoins() as $key => $join) {
         list($join_source, $cond, $type) = $join;
         // JOIN sub-select
         if ($join_source instanceof Result) {
             $join_alias = $this->escapeValue($join_source->getAlias() ? $join_source->getAlias() : '_join_' . ($key + 1), Manager::IDENTIFIER);
             $join_source = "(\n\t" . implode("\n\t", explode("\n", $join_source)) . "\n) {$join_alias}";
         } elseif ($join_source instanceof Literal) {
             $join_source = $join_source->value;
         } elseif (is_scalar($join_source)) {
             $join_source = $this->parseFieldName($join_source, true);
         }
         $type = strtoupper(substr($type, 5));
         $type .= $type === '' ? '' : ' ';
         $source .= $cond instanceof Literal ? "\n{$type}JOIN {$join_source} ON {$cond->value}" : $this->tryDelimite("\n{$type}JOIN {$join_source} ON {$cond}");
     }
     return $source;
 }
Example #2
0
 /**
  * Returns full table name (with prefix) if available.
  * @return string|null
  */
 public function getTable()
 {
     if ($this->source instanceof self) {
         return null;
     }
     return parent::getTable();
 }