Joins the category / post linking table into this queyr.

@param \Magento\Framework\DB\Select $select
@return void
543675
private function joinCategoryIdsTable(\Magento\Framework\DB\Select $select)
    {
        $select->group('entity_id');
        $select->joinInner(
            [self::CAT_PROD_LINK_ALIAS => $this->getTable(self::CAT_PROD_LINK)],
            'e.entity_id = ' . self::CAT_PROD_LINK_ALIAS . '.post_id',
            'category_id'
        );
    }
930894
public function selectDatabase(string $databaseName = ''): void
    {
        $this->selectedDB = $databaseName;
        $this->currentDB = $this->currentLink->select_db($databaseName);

        if (!$this->currentDB) {
            $this->setError(AbstractMySQL::E_NO_DB_SELECTED, __CLASS__);
        }
    }
1219488
private function prepareSelect(array $select)
    {
        if ($select['sql'] instanceof SelectQuery) {
            $columnsCount = count($this->columns);

            $selectColumnsCount = count($select['sql']->getColumns());

            if ($selectColumnsCount and $selectColumnsCount !== $columnsCount) {
                throw new SqlException('INSERT select columns count does not match.'
                                        . ' Expected ' . $columnsCount . ', got ' . $selectColumnsCount);
            }
            [$sql, $params] = $select['sql']->toSql();

            $select['sql'] = $sql;

            $select['params'] = $params;
        }

        return $select;
    }
632011
public function selectMany($select=null)
    {
        $select = LambdaUtils::toSelectCallable($select);

        $result = array();
        foreach($this as $key => $record)
        {
            $temp = call_user_func($select, $record, $key);
            if(is_array($temp) || $temp instanceof \Iterator)
            {
                foreach($temp as $tempitem)
                {
                    $result[] = $tempitem;
                }
            }
            else
            {
                $result[] = $temp;
            }
        }
        return new ArrayList($result);
    }
55314
public function filterQuery(&$selects)
    {
        $model      = $this->config->getDataModel();
        $joins      = $where      = '';
        $columnName = $this->getOption('column_name');

        $relationship = $model->{$this->getOption('relationship')}();
        $from_table   = $this->tablePrefix.$relationship->getRelated()->getTable();
        $field_table  = $columnName.'_'.$from_table;

        //grab the existing where clauses that the user may have set on the relationship
        $relationshipWheres = $this->getRelationshipWheres($relationship, $field_table);

        $where = $this->tablePrefix.$relationship->getQualifiedParentKeyName().
                ' = '.
                $field_table.'.'.$relationship->getPlainForeignKey()
                .($relationshipWheres ? ' AND '.$relationshipWheres : '');

        $selects[] = $this->db->raw('(SELECT '.$this->getOption('select').'
										FROM '.$from_table.' AS '.$field_table.' '.$joins.'
										WHERE '.$where.') AS '.$this->db->getQueryGrammar()->wrap($columnName));
    }
798559
function select($select, $force = false)
    {
        if (is_array($select))
        {
            $select = implode(',', $select);
        }
        if ($this->select == "*" or $force)
        {
            $this->select = $select;
        }
        else
        {
            $this->select = $this->select . ',' . $select;
        }
    }
1359506
public function join($path, $select = null)
    {

        $path = $this->getNameInContext($path);

        $face = $this->getBaseFace()
            ->getElement($path)
            ->getFace();

        $sqlPath = $this->_doFQLTableName($path, ".");

        $qJoin = new JoinQueryFace($sqlPath, $face);

        if(null !== $select){
            $qJoin->setColumns($select);
        }

        $this->addJoin($qJoin);
        return $this;
    }
43535
public void append2SQLSelect(final SQLSelect _sqlSelect)
    {
        if (iWhere != null) {
            final SQLWhere sqlWhere = _sqlSelect.getWhere();
            for (final IWhereTerm<?> term : iWhere.getTerms()) {
                if (term instanceof IWhereElementTerm) {
                    final IWhereElement element = ((IWhereElementTerm) term).getElement();
                    if (element.getAttribute() != null)
                    {
                        final String attrName = element.getAttribute();
                        for (final Type type : types) {
                            final Attribute attr = type.getAttribute(attrName);
                            if (attr != null) {
                                addAttr(_sqlSelect, sqlWhere, attr, term, element);
                                break;
                            }
                        }
                    } else if (element.getSelect() != null) {
                        final IWhereSelect select = element.getSelect();
                        for (final ISelectElement ele : select.getElements()) {
                            if (ele instanceof IBaseSelectElement) {
                                switch (((IBaseSelectElement) ele).getElement()) {
                                    case STATUS:
                                        for (final Type type : types) {
                                            final Attribute attr = type.getStatusAttribute();
                                            if (attr != null) {
                                                addAttr(_sqlSelect, sqlWhere, attr, term, element);
                                                break;
                                            }
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            } else if (ele instanceof IAttributeSelectElement) {
                                final String attrName = ((IAttributeSelectElement) ele).getName();
                                for (final Type type : types) {
                                    addAttr(_sqlSelect, sqlWhere, type.getAttribute(attrName), term, element);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (iOrder != null) {
            final SQLOrder sqlOrder = _sqlSelect.getOrder();
            for (final IOrderElement element: iOrder.getElements()) {
                for (final Type type : types) {
                    final Attribute attr = type.getAttribute(element.getKey());
                    if (attr != null) {
                        final SQLTable table = attr.getTable();
                        final String tableName = table.getSqlTable();
                        final TableIdx tableidx = _sqlSelect.getIndexer().getTableIdx(tableName);
                        sqlOrder.addElement(tableidx.getIdx(), attr.getSqlColNames(), element.isDesc());
                        break;
                    }
                }
            }
        }
    }
565478
final public function select($select = "*") {
      $this->connection();
      if (func_num_args()>1)
         $select = func_get_args();
      else if(is_string($select)) {
         $select = [$select];
      }

      $select_tmp = [];
      foreach ($select as $value) {

         if ( $value===NULL )
            $select_tmp[] = ' NULL ';
         elseif ( gettype( $value )==='boolean' )
            $select_tmp[] = $value ? ' TRUE ' : ' FALSE ';
         elseif ($value instanceof \Closure) {
            $value(new \Daniia\Daniia());
            if (preg_match("/^CASE/", $_ENV['daniia_daniia']->case)) {
               $select_tmp[] = '( '.$_ENV['daniia_daniia']->case.' '.$_ENV['daniia_daniia']->when.' '.$_ENV['daniia_daniia']->else.' END )';
               $_ENV['daniia_daniia']->case = NULL;
            }
            else {
               $select_tmp[] = $_ENV['daniia_daniia']->get_sql();
               $_ENV['daniia_daniia'] = null;
            }
         }
         elseif ( in_array(strtolower(trim($value)), $this->columnsData, true) )
            $select_tmp[] = $value;
         else {
            $select_tmp[] = $value;
         }

      }

      $select = implode(",", $select_tmp);
      $this->select = str_replace("*", $select, $this->select);

      $this->find_first_data = $this->find_save_data = $this->find_delete_data = FALSE;

      $this->get_instance();
      return $this;
   }
636928
public function preSelect(Select $select)
	{
        $sname = 'dms';
        $tableGateway = $this->tableGateway;
        $tableName    = $tableGateway->getTable();
        $tablePrimKey = $this->getPrimaryKey($tableGateway);

        $rawState  = $select->getRawState();
        $columns   = $rawState['columns'];
        if (!in_array('*', $columns) && !in_array($tablePrimKey, $columns))
            // We need primary key for postSelect
            array_unshift($columns, $tablePrimKey);

        if (!$this->getDmsColumns()) {
            // we have not any predefined dms columns
            // - look over dms table that which data is provided for this entity of table
            //   as extra data on dmsTable
            // - the query return left joined results of table rows included dms data as
            //   field and content
            // - later on postSelect we will filter data

            // NOTE: not defined dms columns bring down the performance and resources

            if (!in_array('*', $columns)) {
                $dmsColumns = array_diff($columns, $tableGateway->getColumns());
                if ($dmsColumns) {
                    // we`ve not need all dms columns from table, request specific columns
                    // that are not default table columns and assumed as dms
                    // select user_id, field_on_dms, ....
                    $this->setDmsColumns($dmsColumns);
                    return $this->preSelect($select);
                }
            }

            /*
            SELECT mtp . * , dms.field as dms__field, dms.content as dms__content
            FROM  `typopages_page` AS mtp
            LEFT JOIN  `yimabase_dms` AS dms ON dms.foreign_key = mtp.page_id
            */
            $joinTable = $this->getDmsTable()->table;// get name of dms table

            $expression = new Expression(
                "$sname.foreign_key = ?.?
                AND $sname.model = ?
                "
                , [
                    $tableName, $tablePrimKey,
                    get_class($tableGateway),
                ]
                , [
                    Expression::TYPE_IDENTIFIER,
                    Expression::TYPE_IDENTIFIER
                ]
            );

            $select->join(
                [$sname => $joinTable]//join table name
                ,$expression //conditions
                ,[
                    'dms__content' => 'content',
                    'dms__field'   => 'field',
                ]
                ,'left'
            );

            // used in post select
            $this->setStoredValues(['pk' => $tablePrimKey, 'columns' => $rawState['columns']]);

            $select->columns($columns);

            return; // ===================================================================================
        }

		/*
		 SELECT `sampletable`.*, `dms__image`.`content` AS `image`
 		 FROM `sampletable`
		 LEFT JOIN `yimabase_dms` AS `dms__image`
 		  ON dms__image.foreign_key = `sampletable`.`sampletable_id`
      		 AND dms__image.model   = 'application\\Model\\TableGateway\\Sample'
     		 AND dms__image.field   = 'image'
		*/
		
		// Looking at SELECT requested COLUMNS for any DMS Columns ... {
        #  SELECT [column] FROM ...
		$vColumns  = array_values($columns);
		$dmsFields = $this->getDmsColumns();
		
		if (! array_intersect($vColumns, $dmsFields) && !in_array('*', $vColumns) )
            // We don't have any DMS columns on SELECT expression
			return;
        // ... }

		$tableClass   = get_class($tableGateway);
		$tablePrimKey = $this->getPrimaryKey($tableGateway);

		foreach ($this->getDmsColumns() as $dc) {
			if (($key = array_search($dc, $columns)) !== false ) {
				// we have dms column in select and must remove from SELECT 'dms_column'
				unset($columns[$key]);
			} elseif (!in_array('*', $vColumns)) {
				// we don't need any other dms fields, cause not in SELECT
				continue;
			}
			
			$name = 'Dms__'.$dc;

			$joinTable = $this->getDmsTable()->table;// get name of translation table
			$expression = new Expression("
				$name.foreign_key = ?.?
				AND $name.model = ?
				AND $name.field = ?
				"
				,array(
					$tableName, $tablePrimKey,
					$tableClass,
					$dc
				)
				,array(
					Expression::TYPE_IDENTIFIER,
					Expression::TYPE_IDENTIFIER
				)
			);
			
			$select->join(
				array($name => $joinTable)//join table name
				,$expression //conditions
				,array($dc => 'content') // this way we dont need postSelect replacement
				,'left'
			);
		}
		
		$select->columns($columns);

        // Filter dms columns on where clause:
        // SELECT `user`.`_user_id` AS `_user_id`, `Dms__location`.`content` AS `location`
        // FROM `user` LEFT JOIN `user_dms` AS `Dms__location` ON ...
        // WHERE `nation_code` = '0322358078' AND location = '1' <====== sql can't realize this
        // We use this instead:
        // Dms__location.content = '1'

        /** @var \Zend\Db\Sql\Where $where */
        $where      = $rawState['where'];
        foreach ($where->getPredicates() as $pr)
        {
            /** @var \Zend\Db\Sql\Predicate\Operator $predicate */
            $predicate = $pr[1];
            if (method_exists($predicate, 'getLeft')) {
                $operand = $predicate->getLeft();
                if (in_array($operand, $this->getDmsColumns()))
                    $predicate->setLeft('Dms__'.$operand.'.content');
            } elseif (method_exists($predicate, 'getIdentifier')) {
                $operand = $predicate->getIdentifier();
                if (in_array($operand, $this->getDmsColumns()))
                    $predicate->setIdentifier('Dms__'.$operand.'.content');
            }
        }
	}
1317926
public function afterSelect(Select $event)
    {
        if ($this->isLazyLoaded()) {
            return;
        }
        foreach ($event->getEntityCollection() as $index => $entity) {
            $row = $event->getData()[$index];
            $entity->{$this->propertyName} = $this->getFromMap($row);
        }
    }
390586
protected function executeSelect(Select $select)
    {
        $selectState = $select->getRawState();
        if ($selectState['table'] != $this->table) {
            throw new \RuntimeException('The table name of the provided select object must match that of the table');
        }

        // We don't want use default table columns as default select columns state
        /*if ($selectState['columns'] == array(Select::SQL_STAR)
            && $this->columns !== array()) {
            $select->columns($this->columns);
        }*/

        // apply preSelect features
        $this->featureSet->apply('preSelect', array($select));

        // prepare and execute
        /** @var \Zend\Db\Adapter\Driver\Pdo\Statement $statement */
        $statement = $this->sql->prepareStatementForSqlObject($select);
        $result = $statement->execute();

        // build result set
        $resultSet = clone $this->resultSetPrototype;
        $resultSet->initialize($result);

        // apply postSelect features
        $this->featureSet->apply('postSelect', array($statement, $result, $resultSet));

        return $resultSet;
    }
1296762
public function assignRecord($select)
    {
        $record = $this->getRecordByQuery($select);

        if ($record != false && $record->count() > 0) {
            $this->assign($record->fields);
            return true;
        }

        return false;
    }
573004
public function select(): array
	{
		$sql  = $this->query->getPrefix();
		$sql .= $this->setOperations($this->query->getSetOperations());
		$sql .= $this->query->isDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
		$sql .= $this->columns($this->query->getColumns(), true);
		$sql .= $this->from($this->query->getTable());
		$sql .= $this->joins($this->query->getJoins());
		$sql .= $this->wheres($this->query->getWheres());
		$sql .= $this->groupings($this->query->getGroupings());
		$sql .= $this->havings($this->query->getHavings());
		$sql .= $this->orderings($this->query->getOrderings());
		$sql .= $this->limit($this->query->getLimit());
		$sql .= $this->offset($this->query->getOffset());
		$sql .= $this->lock($this->query->getLock());

		return ['sql' => $sql, 'params' => $this->params];
	}
16313
protected function addPrefixedColumnsToSelect(Select $select, $joinAlias)
    {
        foreach ($this->classTableColumnMap as $columnName => $prefixedColumnName) {
            $select->addColumn($prefixedColumnName, Expr::column($joinAlias, $this->classTable->findColumn($columnName)));
        }
    }
232145
public function selectPdo($select, $param = null)
    {
        $statement = $this->getAdapter()->query($select, ADT::QUERY_MODE_PREPARE);
        $result = $statement->execute($param);

        $resultSet = clone $this->resultSetPrototype;

        return $resultSet->initialize($result);
    }
910593
public function afterSelect(Select $event)
    {
        if ($this->lazyLoad) {
            return;
        }
        $data = $event->data;
        $multiple = $data instanceof RecordList;
        if ($multiple) {
            $data = $event->data->getArrayCopy();
        } else {
            $data = [$data];
        }
        if (empty($data)) {
            return;
        }
        $related = Entity\Manager::getInstance()
            ->get($this->getRelatedEntity());
        $relatedTable = $related->getEntity()->getTableName();
        $class = $related->getEntity()->getClassName();
        $dataCopy = $data;
        foreach ($dataCopy as $key => $row) {

            $pmk =  $this->getEntity()->getPrimaryKey();
            if (isset($row[$pmk]) && is_array($row[$pmk])) {
                $data[$key][$pmk] = reset($row[$pmk]);
            }
            $options = [];
            if (is_array($row)) {
                foreach ($row as $column => $value) {
                    if (preg_match('/^' . $relatedTable . '_(.*)/', $column)) {
                        unset($data[$key][$column]);
                        $name = str_replace($relatedTable . '_', '', $column);
                        $options[$name] = $value;
                    }
                }
            }
            $data[$key][$this->getPropertyName()] = new $class($options);
        }

        if ($multiple) {
            $event->data = new RecordList(['data' => $data]);
        } else {
            $event->data = reset($data);
        }
    }