create query begining
@return $this
488577
public function prefixQuery()
    {
        $options = $this->getOptions();
        
        if($this->validateOptions($options)) {
            
            if(array_key_exists('language' , $options)) {
               $this->language = $this->setLanguageCondition($options['language'], true);
            }
            
            $this->queryPrefix = $this->initQuery();
        }
        return $this;

    }
1299331
private function createQueryFilter()
    {
        if (count($this->queryFilter()) > 0) {
            foreach ($this->queryFilter() as $filter => $parameters) {
                if (!is_array($parameters)) {
                    $parameters = [$parameters];
                }
                $this->query = call_user_func_array([$this->query, $filter], $parameters);
            }
        }
    }
160441
protected function beginQuery()
    {
        $autoSlave = $this->db->isAutoSlave();
        if ($autoSlave) {
            $this->db->switchConnection('slave');
        }

        $reconnect = $this->db->getOption('reconnect');
        $reconnectRetries = $this->db->getOption('reconnect_retries', 3);
        $reconnectDelayMS = $this->db->getOption('reconnect_delay_ms', 1000);

        while (true) {
            $e = null;
            $errorCode = null;
            $errorInfo = null;
            $result = null;

            $isReconnectError = false;
            try {
                $this->prepare();
                $result = $this->statement->execute($this->params ? $this->params : $this->positionParams);
            } catch (\Exception $e) {
            }

            if ($result === false || !$e) {
                $errorCode = $this->statement->errorCode();
                $errorInfo = $this->statement->errorInfo();
            }

            $isReconnectError = Util::checkReconnectError($errorCode, $errorInfo, $e);

            // reconnect
            if ($reconnect && $isReconnectError && $reconnectRetries > 0) {
                $reconnectRetries--;
                $this->statement = null;
                $this->db->close();
                $reconnectDelayMS && usleep($reconnectDelayMS * 1000);
                continue;
            }

            break;
        }

        if ($autoSlave) {
            $this->db->switchConnection();
        }

        if ($e) {
            $this->db->logError(sprintf('Statement exception error #%s: %s', $e->getCode(), $e->getMessage()));
            throw $e;
        }

        if ($result === false) {
            $errorMsg = sprintf('Statement execute error #%s: %s', $errorInfo[0], $errorInfo[2]);
            $this->db->logError($errorMsg);
            throw new Exception($errorMsg);
        }
    }
1200466
public function reset()
    {
        $this->builder->resetQueryParts();
        $this->relations = [];
        $this->queryString = null;
        $this->queryParams = [];
        $this->casts = [];
        $this->resetBinds();

        $this->setQuery();
        $this->fields();

        return $this;
    }
85985
function query() {
        if(empty($this->sql)) {
            $this->_constructSql();
        }
        list($sql, $param) = $this->_constructSql();
        $this->_reset();
        return $this->execute($sql, $param);
    }
645476
public function buildQuery()
    {
        $model = $this->model;
        $query = $model::query();

        // perform joins
        if (is_array($this->join)) {
            foreach ($this->join as $condition) {
                list($joinModel, $column, $foreignKey) = $condition;
                $query->join($joinModel, $column, $foreignKey);
            }
        }

        // sanitze and set the filter
        $filter = $this->parseFilterInput($this->filter);
        $query->where($filter);

        // performs a search using LIKE queries
        // WARNING use sparingly, these queries are expensive
        if (!empty($this->search) && is_string($this->search) && property_exists($model, 'searchableProperties')) {
            $w = [];
            $search = addslashes($this->search);
            foreach ($model::$searchableProperties as $name) {
                $w[] = "`$name` LIKE '%$search%'";
            }

            if (count($w) > 0) {
                $query->where('('.implode(' OR ', $w).')');
            }
        }

        // eager loading
        foreach ($this->expand as $k) {
            $property = $model::getProperty($k);
            if ($property && isset($property['relation'])) {
                if (isset($property['id_property'])) {
                    $query->with($property['id_property']);
                } else {
                    $query->with($k);
                }
            }
        }

        if (isset($this->sort)) {
            $query->sort($this->sort);
        }

        // calculate limit and offset
        $start = ($this->page - 1) * $this->perPage;
        $query->start($start)->limit($this->perPage);

        return $query;
    }
1067426
public function useInitialQueryFromTypoScript(): QueryBuilder
    {
        if ($this->typoScriptConfiguration->getSearchInitializeWithEmptyQuery() || $this->typoScriptConfiguration->getSearchQueryAllowEmptyQuery()) {
            // empty main query, but using a "return everything"
            // alternative query in q.alt
            $this->useAlternativeQuery('*:*');
        }

        if ($this->typoScriptConfiguration->getSearchInitializeWithQuery()) {
            $this->useAlternativeQuery($this->typoScriptConfiguration->getSearchInitializeWithQuery());
        }

        return $this;
    }
89063
protected function startQuery()
    {
        $sessionOK = $this->initialiseSession();
        if ($sessionOK) {
            $searchReplyString = $this->fetchURL($this->pazpar2SearchURL());
            $searchReply = GeneralUtility::xml2array($searchReplyString);

            if ($searchReply) {
                $status = $searchReply['status'];
                if ($status === 'OK') {
                    $this->queryIsRunning = true;
                } else {
                    GeneralUtility::devLog('pazpar2 search command status is not "OK" but "' . $status . '"', 'pazpar2', 3);
                }
            } else {
                GeneralUtility::devLog('could not parse pazpar2 search reply', 'pazpar2', 3);
            }
        }
    }
965374
public function begin(Context $context = null)
    {
        $this->getDBQueryBuilder($context)->go(null, 'begin');
        
        return $this;
    }
527211
public function enableQueryLog() {
		$this->loggingQueries = true;

		if ( ! $this->logger ) {
			$this->setLogger( new QueryLogger );
		}

		return $this;
	}
223367
public function create()
    {
        $this->sql = new PhiberQueryWriter("create", [
            "table"  => $this->table,
            "fields" => $this->fields,
            "values" => $this->fieldsValues
        ]);

        if ($this->phiberConfig->verifyExecuteQueries()) {
            $stmt = $this->PDO->prepare($this->sql);

            for ($i = 0; $i < count($this->fields); $i++) {
                if ($this->fieldsValues[$i] != null) {
                    $stmt->bindValue($this->fields[$i], $this->fieldsValues[$i]);
                }
            }
            if ($stmt->execute()) {
                return $this->PDO->lastInsertId();
            }
        }

        return false;
    }
1067318
public function reset()
    {
        $this->queryType = null;
        $this->offset = 0;
        $this->limit = null;
        $this->joins = array();
        $this->fields = array();
        $this->fromTable = null;
        $this->wheres = array();
        $this->orderBy = null;
        $this->groupBy = array();
        $this->having = array();
        return $this;
    }
827152
public function begin() {
        if ($this->transactionLevel < 0) throw new RuntimeException('Negative transaction nesting level detected: '.$this->transactionLevel);

        if (!$this->transactionLevel)
            $this->execute('start transaction');

        $this->transactionLevel++;
        return $this;
    }
135096
final protected function build_query(){
        $select = empty($this->_select) ? $this->default_select() : implode(', ', $this->_select);
        $calc = $this->_calc_rows ? ' SQL_CALC_FOUND_ROWS' : '';
        $distinct = $this->_distinct ? sprintf('DISTINCT(%s)', $this->escape_column_name($this->_distinct)) : '';
        $from = empty($this->_from) ? $this->table : $this->_from;
        // Build query
        $sql = <<<SQL
          SELECT{$calc} {$distinct} {$select} FROM {$from}
SQL;
        // Add join
        $join = [];
        if( !empty($this->_join) ){
            $join = $this->_join;
        }else{
            $default_join = $this->default_join();
            if( !empty($default_join) ){
                $join = $default_join;
            }
        }
        foreach($join as list($table, $on, $method)){
            $method = 'INNER' === strtoupper($method) ? 'INNER' : 'LEFT';
            $sql .= <<<SQL
            {$method} JOIN {$table}
            ON {$on}
SQL;
        }
        // Add where
        if( !empty($this->_wheres) ){
            $where_clause = $this->build_where($this->_wheres);
            $sql .= <<<SQL
            WHERE {$where_clause}
SQL;
        }
        // Add group by
        if( !empty($this->_group_by) ){
            $group_by = implode(', ', $this->_group_by);
            $sql .= <<<SQL
            GROUP BY {$group_by}
SQL;
        }
        // Add order by
        if( !empty($this->_order_by) ){
            $order_by = implode(', ', $this->_order_by);
            $sql .= <<<SQL
            ORDER BY {$order_by}
SQL;
        }
        // Add limit
        if( !empty($this->_limit) ){
            list($per_page, $offset) = $this->_limit;
            $limit = <<<SQL
            LIMIT %d, %d
SQL;
            $sql .= sprintf($limit, $offset, $per_page);
        }
        return $sql;
    }
911030
public function newRawQuery()
    {
        $builder = $this->newEloquentBuilder($this->newBaseQueryBuilder());

        // Once we have the query builders, we will set the model instances
        // so the builder can easily access any information it may need
        // from the model while it is constructing and executing various
        // queries against it.
        $builder->setModel($this)->with($this->with);
        return $builder;
    }
93617
public function prefixQuery() {
        $options = $this->getOptions();

        if ($this->validateOptions($options)) {

            if (array_key_exists('language', $options)) {
                $this->userLanguage = $this->setLanguageCondition($options['language'], true);
            }
            if (array_key_exists('defaultLanguage', $options)) {
                $this->defaultLanguage = $this->setLanguageCondition($options['defaultLanguage'], true);
            }
            if (array_key_exists('model', $options)) {
                $this->model = $options['model'];
            }
            $this->queryPrefix = $this->initQuery();
        }
        return $this;
    }
646871
protected function finishQuery() {
        
        $this->query .= ' ' . $this->addLimit($this->criteriaList->getLimit() , $this->criteriaList->getOffset()) .' ) ' . 
                $this->operationSeparator .
                $this->getDriverEscaper()->dbCommand('AS') .
                ' subQuery ) ' . $this->operationSeparator . 
                $this->addSort($this->criteriaList->getSort());
        
        return $this;
    }