/**
  * @return IStaticQuery
  * @throws InvalidQueryException
  */
 public function format()
 {
     if (count($querySelectList = $this->selectQuery->getSelectList()) === 0) {
         throw new InvalidQueryException('Nothing to select!');
     }
     $prettyPrint = ['', '', ' '];
     if (false) {
         $prettyPrint = ["\t", "\n\t", "\n"];
     }
     $sql[] = 'SELECT';
     if ($this->selectQuery->isDistinct()) {
         $sql[] = 'DISTINCT';
     }
     $parameterList = [];
     $selectList = [];
     foreach ($querySelectList as $select) {
         $selectList[] = $format = $select->format($this->formatterProvider);
         $parameterList = array_merge($parameterList, $format->getParameterList());
     }
     $sql[] = $prettyPrint[0] . implode(',' . $prettyPrint[1], $selectList);
     if (count($queryTableList = $this->selectQuery->getTableList()) > 0) {
         $sql[] = 'FROM';
         $tableList = [];
         foreach ($queryTableList as $table) {
             $tableList[] = $format = $table->format($this->formatterProvider);
             $parameterList = array_merge($parameterList, $format->getParameterList());
         }
         $sql[] = $prettyPrint[0] . implode(',' . $prettyPrint[1], $tableList);
     }
     if (($where = $this->selectQuery->getWhere()) !== null) {
         $sql[] = 'WHERE';
         $sql[] = $prettyPrint[0] . ($format = $where->format($this->formatterProvider));
         $parameterList = array_merge($parameterList, $format->getParameterList());
     }
     return $this->sql(implode($prettyPrint[2], $sql), $parameterList);
 }
Example #2
0
 public function format(IFormatterProvider $formatterProvider)
 {
     $fragmentFormat = $this->fragment->format($formatterProvider);
     $queryFormat = $this->selectQuery->format($formatterProvider);
     return $this->sql($fragmentFormat . ' IN ' . $queryFormat, array_merge($fragmentFormat->getParameterList(), $queryFormat->getParameterList()));
 }