Gets the select object to be used by the validator.
If no select object was supplied to the constructor,
then it will auto-generate one from the given table,
schema, field, and adapter options.

@return Zend_Db_Select The Select object which will be used
177234
public function getSelect()
    {
        if (null === $this->_select) {
            $db = $this->getAdapter();

            /**
             * Build select object
             */
            $select = new \Zend_Db_Select($db);
            $select->from('gems__surveys', array('gsu_export_code'))
                    ->where('gsu_export_code = ?')
                    ->where('gsu_id_survey NOT IN (?)', implode(', ', $this->_tested))
                    ->limit(1);

            // \MUtil_Echo::track($select->__toString());
            $this->_select = $select;
        }
        return $this->_select;
    }
1238844
protected function getOptions()
	{
		$options = array();

		$select = new HtmlSelect;

		// Try to inject the text object into the field
		try
		{
			$select->setText($this->getText());
		}
		catch (\RuntimeException $exception)
		{
			// A Text object was not set, ignore the error and try to continue processing
		}

		/** @var \SimpleXMLElement $option */
		foreach ($this->element->children() as $option)
		{
			// Only add <option /> elements.
			if ($option->getName() != 'option')
			{
				continue;
			}

			$text = $this->translateOptions
				? $this->getText()->alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname))
				: trim((string) $option);

			// Create a new option object based on the <option /> element.
			$tmp = $select->option((string) $option['value'], $text, 'value', 'text', ((string) $option['disabled'] == 'true'));

			// Set some option attributes.
			$tmp->class = (string) $option['class'];

			// Set some JavaScript option attributes.
			$tmp->onclick = (string) $option['onclick'];

			// Add the option object to the result set.
			$options[] = $tmp;
		}

		reset($options);

		return $options;
	}
667280
public function getSelectQuery()
    {
        $sql = 'SELECT ' . $this->getSelect();
        $sql .= "\nFROM " . $this->getFrom();
        if ($this->where) {
            $sql .= "\nWHERE " . $this->getWhere();
        }
        if ($this->groupBy) {
            $sql .= "\nGROUP BY " . $this->getGroupBy();
        }
        if ($this->having) {
            $sql .= "\nHAVING " . $this->getHaving();
        }
        if ($this->orderBy) {
            $sql .= "\nORDER BY " . $this->getOrderBy();
        }
        if ($this->limit) {
            $sql .= "\nLIMIT " . $this->getLimit();
        }

        return $sql;
    }
636501
public function getSelect()
    {
        $select = $this->db->select();

        $fields['answered'] = new \Zend_Db_Expr("SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NOT NULL
            THEN 1 ELSE 0 END
            )");
        $fields['missed']   = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND
                 gto_completion_time IS NULL AND
                 gto_valid_until < CURRENT_TIMESTAMP AND
                 (gto_valid_from IS NOT NULL AND gto_valid_from <= CURRENT_TIMESTAMP)
            THEN 1 ELSE 0 END
            )');
        $fields['open']   = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NULL AND
                gto_valid_from <= CURRENT_TIMESTAMP AND
                (gto_valid_until >= CURRENT_TIMESTAMP OR gto_valid_until IS NULL)
            THEN 1 ELSE 0 END
            )');
        $fields['total'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND (
                    gto_completion_time IS NOT NULL OR
                    (gto_valid_from IS NOT NULL AND gto_valid_from <= CURRENT_TIMESTAMP)
                )
            THEN 1 ELSE 0 END
            )');
        /*
        $fields['future'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NULL AND gto_valid_from > CURRENT_TIMESTAMP
            THEN 1 ELSE 0 END
            )');
        $fields['unknown'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1 AND gto_completion_time IS NULL AND gto_valid_from IS NULL
            THEN 1 ELSE 0 END
            )');
        $fields['is']      = new \Zend_Db_Expr("'='");
        $fields['success'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 1
            THEN 1 ELSE 0 END
            )');
        $fields['removed'] = new \Zend_Db_Expr('SUM(
            CASE
            WHEN grc_success = 0
            THEN 1 ELSE 0 END
            )');
        // */

        $fields['filler'] = new \Zend_Db_Expr('COALESCE(gems__track_fields.gtf_field_name, gems__groups.ggp_name)');

        $select = $this->db->select();
        $select->from('gems__tokens', $fields)
                ->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array())
                ->joinInner('gems__rounds', 'gto_id_round = gro_id_round',
                        array('gro_round_description', 'gro_id_survey'))
                ->joinInner('gems__surveys', 'gro_id_survey = gsu_id_survey',
                        array('gsu_survey_name'))
                ->joinInner('gems__groups', 'gsu_id_primary_group =  ggp_id_group', array())
                ->joinLeft('gems__track_fields', 'gto_id_relationfield = gtf_id_field AND gtf_field_type = "relation"', array())
                ->group(array('gro_id_order', 'gro_round_description', 'gsu_survey_name', 'filler'));

        $filter = $this->getSearchFilter();
        if (array_key_exists('fillerfilter', $filter)) {
            $select->having('filler = ?', $filter['fillerfilter']);
        }

        return $select;
    }
358780
protected function getDbAdapter()
    {
        if ( null === $this->dbAdapter )
        {
            $this->dbAdapter = $this->getServiceManager()
                                    ->get( 'Zend\Db\Adapter\Adapter' );
        }

        return $this->dbAdapter;
    }
511070
public function buildSelectSQL()
	{
		$where = $this->parseCondition(isset($this->operationOption['where']) ? $this->operationOption['where'] : '');
		if ('' !== $where)
		{
			$where = 'where ' . $where . ' ';
		}
		return 'select ' . $this->parseDistinct()
				. $this->parseFieldBefore()
				. $this->parseField(null,'*')
				. 'from '
				. $this->parseTable() . ' '
				. $this->parseJoin()
				. $where
				. $this->parseGroup()
				. $this->parseHaving()
				. $this->parseOrder()
				. $this->parseLimit()
				. $this->parseLock()
				;
	}
840283
protected function _initSelect()
    {
        parent::_initSelect();
        $this->addFieldToSelect(['path', 'value'])->addFieldToFilter('scope', $this->scope);

        if ($this->scopeCode !== null) {
            $this->addFieldToFilter('scope_code', $this->scopeCode);
        }

        return $this;
    }
655055
public function getValidator() {
        if (!$this->_validator instanceof xPDOValidator) {
            $validatorClass = $this->getOption(xPDO::OPT_VALIDATOR_CLASS, null, 'xPDO\\Validation\\xPDOValidator');
            if ($validatorClass = $this->xpdo->loadClass($validatorClass, '', false, true)) {
                $this->_validator = new $validatorClass($this);
            }
        }
        return $this->_validator;
    }
747657
public function selectOne()
    {
        $this->setLimit(1);

        $query = 'SELECT ' . $this->getQueryFields() . ' FROM ' . $this->getTable() . ' ' . $this->getQueryWhere() . ' ' . $this->getQueryOrderBy() . ' ' . $this->getQueryLimit();

        $statement = $this->db->prepare($query);
        $statement->execute($this->binds);

        $this->clear();

        if ($statement->rowCount() === 0) {
            throw new ExceptionNoData('No data for current query! (query: ' . $query . ', bind: ' . json_encode($this->binds) . ')', 10001);
        }

        //~ Create new object, set data & save it in cache
        return $this->newDataInstance($statement->fetchObject(), true);
    }
108298
public function getSelectRegister()
    {
        return ($this->isValueNumeric('nb_site_id') && $this->isValueNumeric('nb_role_id') && $this->isValueNumeric('nb_language_id'))
            ? $this->buildSentence(
                    'select * '
                    . 'from nb_site_role_lang '
                   . "where nb_site_id=%nb_site_id\$d "
                     . "and nb_role_id=%nb_role_id\$d "
                     . "and nb_language_id=%nb_language_id\$d "
              )
            : null;
    }
883664
protected function getTable()
	{
		$table = parent::getTable();

		if ($table instanceof SelectQuery) return "(" . $table->get(false) . ")";

		return $table;
	}
506220
protected function checkSelect(){
        return $this->select = is_array($this->select) ? $this->select :  [$this->select];
    }
492210
function select($column0=null, $_=null){
        $obj = new SelectRule(new Context($this->connection));
        if($column0 == null){
            $args = ['*'];
        }elseif(is_array($column0)){
            $args = $column0;
        }else{
            $args = func_get_args();
        }
        foreach ($args as &$arg){
            $arg = DB::wrap($arg);
            if($arg == '*'){
                continue;
            }
        }
        return $obj->select(implode(',', $args));
    }
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;
    }
247460
protected function getSelect()
    {
        $html = '<select>';

        if (is_array($this->window['all'])) {
            $html .= $this->getOptionLinks($this->window['all']);
        }

        $html .= '</select>';

        return $html;
    }
973126
public function getAdapter()
    {
        /**
         * Check for an adapter being defined. if not, fetch the default adapter.
         */
        if ($this->_adapter === null) {
            $this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
            if (null === $this->_adapter) {

                throw new Zend_Validate_Exception('No database adapter present');
            }
        }
        return $this->_adapter;
    }
1153301
public function getSelect()
    {
        $ret = parent::getSelect();
        $categoryDirectory = $this->getItemDirectory()->getComponent();

        $refData = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData(
            Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'),
            'Category'
        );

        $ret->join($refData['tableName'],
            "{$refData['refTableName']}.{$refData['refItemColumn']} = "
                ."{$refData['tableName']}.{$refData['itemColumn']}", array()
        );

        $refDataItem = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData(
            Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'),
            'Item'
        );

        $ret->where(
            $refDataItem['tableName'].'.'.$refDataItem['itemColumn'].' = ?',
            $this->_getItemDetail()->row->id
        );

        return $ret;
    }