コード例 #1
0
 /**
  * @throws \Exception
  *
  * @return string
  */
 public function convert()
 {
     $parsed = $this->sqlParser->parse($this->sql);
     if (false === $parsed) {
         throw new \Exception('SQL query is not valid');
     }
     $results = [];
     foreach ($parsed as $section => $data) {
         if ($this->converterFactory->canCreate($section)) {
             $converter = $this->converterFactory->create($section);
             $results = array_merge($results, $converter->convert($data));
         }
     }
     $table = current(array_filter($results, function ($item) {
         return 'table' === $item['name'];
     }));
     unset($results[array_search($table, $results)]);
     array_unshift($results, $table);
     foreach ($results as $function) {
         $args = isset($function['args']) ? $function['args'] : [];
         $this->generator->addFunction($function['name'], $args);
     }
     $this->generator->addFunction('get');
     return $this->generator->generate();
 }
コード例 #2
0
 public function convert($select)
 {
     if (count($select) == 1) {
         $value = $this->getValueWithoutQuotes($select[0]);
         if ('*' === $value) {
             return [];
         }
         unset($value);
     }
     $s = [];
     foreach ($select as $item) {
         if ('colref' === $item['expr_type']) {
             $value = $this->getValueWithoutQuotes($item);
             if (isset($item['alias']) && is_array($item['alias'])) {
                 $value .= ' AS ' . $this->getValueWithoutQuotes($item['alias'], 'name');
             }
             $s[] = $value;
         } elseif ('aggregate_function' === $item['expr_type'] || 'function' === $item['expr_type']) {
             $function = strtoupper($item['base_expr']);
             $value = $function . '(' . implode(', ', array_column($item['sub_tree'], 'base_expr')) . ')';
             if (isset($item['alias']) && is_array($item['alias'])) {
                 $value .= ' AS ' . $item['alias']['name'];
             }
             $generator = new Generator('DB');
             $generator->addFunction('raw', [$value]);
             $s[] = $generator;
         }
     }
     if (is_array($s) && count($s)) {
         return [$this->format('select', $s)];
     }
     throw new \Exception('Not valid select');
 }
コード例 #3
0
 /**
  * @return string
  */
 public function convert()
 {
     $parsed = $this->sqlParser->parse($this->sql);
     if (false === $parsed) {
         throw new \Exception('SQL query is not valid');
     }
     foreach ($parsed as $section => $data) {
         if ($this->converterFactory->canCreate($section)) {
             $converter = $this->converterFactory->create($section);
             $result = $converter->convert($data);
             foreach ($result as $function) {
                 $args = isset($function['args']) ? $function['args'] : [];
                 $this->generator->addFunction($function['name'], $args);
             }
         }
     }
     $this->generator->addFunction('get');
     return $this->generator->generate();
 }