Exemplo n.º 1
0
 /**
  * @param string $str
  * @return NQLQuery
  * @throws SyntaxErrorException
  */
 public static function parse($str) : NQLQuery
 {
     /** @var NQLQuery $query */
     $query = new NQLQuery();
     $match = [];
     $wasFound = preg_match(self::$regSearchQuery, $str, $match);
     if ($wasFound) {
         if (array_key_exists('select', $match) && !empty($match['select'])) {
             $query->select = Select::parse($match['select']);
         } else {
             $query->select = Select::getBlank();
         }
         if (array_key_exists('where', $match)) {
             $query->where = Where::parse($match['where']);
         } else {
             $query->where = Where::getBlank();
         }
         if (array_key_exists('limit', $match) && !empty($match['limit'])) {
             $query->limit = $match['limit'];
         }
         if (array_key_exists('offset', $match) && !empty($match['offset'])) {
             $query->offset = $match['offset'];
         }
         $query->from = From::parse($match['from']);
         if (array_key_exists('orderby', $match) && !empty($match['orderby'])) {
             $query->orderBy = OrderBy::parse($match['orderby']);
         } else {
             $query->orderBy = OrderBy::getBlank();
         }
     } else {
         throw new SyntaxErrorException('Incorrect query');
     }
     return $query;
 }
Exemplo n.º 2
0
 /**
  * @param Select $select
  * @param Where $where
  * @param OrderBy $orderBy
  * @return Column[]
  */
 private function getAllColumns(Select $select, Where $where, OrderBy $orderBy) : array
 {
     $columns = [];
     foreach ($select->getColumns() as $column) {
         $columns[$column->getFullName()] = $column;
     }
     $whereColumns = $this->getAllColumnsFromWhere($where->getConditions());
     foreach ($whereColumns as $column) {
         $columns[$column->getFullName()] = $column;
     }
     foreach ($orderBy->getColumns() as $column) {
         $columns[$column->getFullName()] = $column;
     }
     return $columns;
 }