@param SqlWalker $sqlWalker

@return string
11822
public function getSql(SqlWalker $sqlWalker)
    {
        return sprintf("CAST(%s AS %s)",
            $this->first->dispatch($sqlWalker),
            $this->second
        );
    }
133933
protected function prepareFragment(FragmentInterface $context): string
    {
        if ($context instanceof BuilderInterface) {
            //Nested queries has to be wrapped with braces
            return '(' . $context->sqlStatement($this) . ')';
        }

        if ($context instanceof ExpressionInterface) {
            //Fragments does not need braces around them
            return $context->sqlStatement($this);
        }

        return $context->sqlStatement();
    }
1042447
public function select(SQLStatement $select): string
    {
        $limit = $select->getLimit();

        if ($limit <= 0) {
            return parent::select($select);
        }

        $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
        $sql .= $this->handleColumns($select->getColumns());
        $sql .= ' FROM ';
        $sql .= $this->handleTables($select->getTables());
        $sql .= $this->handleJoins($select->getJoins());
        $sql .= $this->handleWheres($select->getWheres());
        $sql .= $this->handleGroupings($select->getGroupBy());
        $sql .= $this->handleOrderings($select->getOrder());
        $sql .= $this->handleHavings($select->getHaving());

        $offset = $select->getOffset();

        if ($offset < 0) {
            return 'SELECT * FROM (' . $sql . ') M1 WHERE ROWNUM <= ' . $limit;
        }

        $limit += $offset;
        $offset++;

        return 'SELECT * FROM (SELECT M1.*, ROWNUM AS OPIS_ROWNUM FROM (' . $sql . ') M1 WHERE ROWNUM <= ' . $limit . ') WHERE OPIS_ROWNUM >= ' . $offset;
    }
638587
private function getSourceName($source): string
    {
        list($sourceAlias, $sourceName) = $this->dialect()->parseTable($source);

        if (($sourceName instanceof SelectQuery) and !$sourceAlias) {
            throw new SqlException('JOIN source table should have an alias name.');
        }

        return $sourceAlias ?: $sourceName;
    }
6605
public function update(SQLStatement $update): string
    {
        $sql = 'UPDATE ';
        $sql .= $this->handleTables($update->getTables());
        $sql .= $this->handleJoins($update->getJoins());
        $sql .= $this->handleSetColumns($update->getColumns());
        $sql .= $this->handleWheres($update->getWheres());

        return $sql;
    }
209499
public function getSqlString(PlatformInterface $adapterPlatform = null)
    {
        $adapterPlatform = ($adapterPlatform) ? : new Sql92;
        $table = $this->table;
        $table = $adapterPlatform->quoteIdentifier($table);

        $set = $this->set;

        $setSql = [];
        foreach ($set as $col => $val) {
            if ($val instanceof Predicate\Expression) {
                $exprData = $this->processExpression($val, $adapterPlatform);
                $setSql[] = $adapterPlatform->quoteIdentifier($col) . ' = ' . $exprData;
            } elseif ($val === null) {
                $setSql[] = $adapterPlatform->quoteIdentifier($col) . ' = NULL';
            } else {
                $setSql[] = $adapterPlatform->quoteIdentifier($col) . ' = ' . $adapterPlatform->quoteValue($val);
            }
        }
        $set = implode(', ', $setSql);

        $sql = sprintf($this->specifications[self::SPECIFICATION_UPDATE], $table, $set);
        if ($this->where->count() > 0) {
            $whereParts = $this->processExpression($this->where, $adapterPlatform, null, null, 'where');
            $sql .= ' ' . sprintf($this->specifications[self::SPECIFICATION_WHERE], $whereParts);
        }

        $optionParts = $this->processOption($adapterPlatform, null, null);
        if (is_array($optionParts)) {
            $sql .= ' ' . $this->createSqlFromSpecificationAndParameters(
                $this->specifications[self::SPECIFICATION_OPTION],
                $optionParts
            );
        }

        return $sql;
    }
1158254
public function getStructureSize(BytesWalker $walker)
    {
        $marker = $walker->read(1);

        // if tiny size, no more bytes to read, the size is encoded in the low nibble
        if ($this->isMarkerHigh($marker, Constants::STRUCTURE_TINY)) {
            return $this->getLowNibbleValue($marker);
        }
    }
349260
public function getRawQuery()
    {
        $sql = array();

        foreach ($this->getClauses() as $clause) {
            if (!$clause->isEmpty()) {
                $sql[] = $clause;
            }
        }

        return implode(' ', $sql);
    }
755432
public static function highlight(string $sql): string
	{
		static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|SHOW|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE|START\s+TRANSACTION|COMMIT|ROLLBACK|(?:RELEASE\s+|ROLLBACK\s+TO\s+)?SAVEPOINT';
		static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE';
		$sql = ' ' . $sql . ' ';
		$sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8');
		$sql = preg_replace_callback(sprintf('#(/\\*.+?\\*/)|(?<=[\\s,(])(%s)(?=[\\s,)])|(?<=[\\s,(=])(%s)(?=[\\s,)=])#is', $keywords1, $keywords2), function ($matches) {
			if (!empty($matches[1])) { // comment
				return '<em style="color:gray">' . $matches[1] . '</em>';
			}

			if (!empty($matches[2])) { // most important keywords
				return '<strong style="color:#2D44AD">' . $matches[2] . '</strong>';
			}

			if (!empty($matches[3])) { // other keywords
				return '<strong>' . $matches[3] . '</strong>';
			}
		}, $sql);

		return trim((string) $sql);
	}
216732
public static function getDBHelper(string $driver): string
    {
        $drivers = [
            'pdo_mysql'  => MySQL::class,
            'mysql'      => MySQL::class,
            'mysql2'     => MySQL::class,

            'pdo_pgsql'  => PostgreSQL::class,
            'pgsql'      => PostgreSQL::class,
            'postgres'   => PostgreSQL::class,
            'postgresql' => PostgreSQL::class,

            'pdo_sqlsrv' => SQLServer::class,
            'mssql'      => SQLServer::class,
        ];

        if (!array_key_exists($driver, $drivers)) {
            throw new \InvalidArgumentException("$driver unknown");
        }

        return $drivers[$driver];
    }
883048
private function getAllUrlAliasesQuery(): string
    {
        $existingAliasesQueryBuilder = $this->connection->createQueryBuilder();
        $innerQueryBuilder = $this->connection->createQueryBuilder();

        return $existingAliasesQueryBuilder
            ->select('tmp.id')
            ->from(
                // nest subquery to avoid same-table update error
                '(' . $innerQueryBuilder->select('id')->from($this->table)->getSQL() . ')',
                'tmp'
            )
            ->getSQL();
    }
848913
public function toString()
    {
        if (!$this->_parts['table']) {
            throw new SqlException("Invalid `TRUNCATE` statement, missing `TABLE` clause.");
        }

        return 'DELETE' . $this->_buildClause('FROM', $this->dialect()->names($this->_parts['table'])) . ';' .
            'DELETE' . $this->_buildClause('FROM', $this->dialect()->names('SQLITE_SEQUENCE')) .
                ' WHERE name=' . $this->dialect()->names($this->_parts['table']);
    }
165063
public function engineCompat(string $sql): string
    {
        $sql = $this->c::mbTrim($sql);

        if (!preg_match('/^CREATE\s+TABLE\b/ui', $sql)) {
            return $sql; // Not applicable.
        }
        $sql = preg_replace('/\bENGINE\=[%a-z0-9_\-]*/ui', '', $sql);

        if (!preg_match('/\bFULLTEXT\s+KEY\b/ui', $sql) || version_compare($this->wp->db_version(), '5.6.4', '>=')) {
            // MySQL v5.6.4+ supports fulltext indexes w/ InnoDB. See: <http://bit.ly/ZVeF42>
            $sql = preg_replace('/;$/u', ' ENGINE=InnoDB;', $sql);
        } else {
            $sql = preg_replace('/;$/u', ' ENGINE=MyISAM;', $sql);
        }
        return $sql;
    }
959757
protected function getEmptiedQuery(string $sql): string
    {
        // see the reason why in Vision_Store_Adapter_ZendDbSelect::getMetaData
        //$sql = str_replace("('__innerselect'='__innerselect')", '(1=0)', $sql);

        $sql = preg_replace('/(\r\n|\r|\n|\t)+/', ' ', strtolower($sql));
        $sql = trim($sql ?: '');
        $sql = preg_replace('/\s+/', ' ', $sql) ?: '';

        $replace_regexp = "LIMIT[\s]+[\d]+((\s*,\s*\d+)|(\s+OFFSET\s+\d+)){0,1}";

        $search_regexp = "$replace_regexp";
        if (preg_match("/$search_regexp/i", $sql) < 1) {
            // Limit is not already present
            $sql .= ' LIMIT 0';
        } else {
            // replace first if offset exists, then if not
            //preg_match_all("/($search_regexp)/i", $sql, $matches, PREG_PATTERN_ORDER);
            //var_dump($matches);

            $sql = preg_replace("/($replace_regexp)/i", 'LIMIT 0', $sql) ?: '';
        }

        return $sql;
    }
1295641
public static function slaver()
	{
		static $slaver = null;
		if (is_null($slaver)) $slaver = new SqlSlaver(self::$ds_slaver);
		return $slaver;
	}
834688
public function insert(SQLStatement $insert): string
    {
        $columns = $this->handleColumns($insert->getColumns());

        $sql = 'INSERT INTO ';
        $sql .= $this->handleTables($insert->getTables());
        $sql .= ($columns === '*') ? '' : ' (' . $columns . ')';
        $sql .= $this->handleInsertValues($insert->getValues());

        return $sql;
    }
272451
public function select(SQLStatement $select): string
    {
        $limit = $select->getLimit();

        if ($limit <= 0) {
            return parent::select($select);
        }

        $offset = $select->getOffset();

        if ($offset < 0) {
            $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
            $sql .= 'TOP ' . $limit . ' ';
            $sql .= $this->handleColumns($select->getColumns());
            $sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
            $sql .= ' FROM ';
            $sql .= $this->handleTables($select->getTables());
            $sql .= $this->handleJoins($select->getJoins());
            $sql .= $this->handleWheres($select->getWheres());
            $sql .= $this->handleGroupings($select->getGroupBy());
            $sql .= $this->handleOrderings($select->getOrder());
            $sql .= $this->handleHavings($select->getHaving());

            return $sql;
        }

        $order = trim($this->handleOrderings($select->getOrder()));

        if (empty($order)) {
            $order = 'ORDER BY (SELECT 0)';
        }

        $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
        $sql .= $this->handleColumns($select->getColumns());
        $sql .= ', ROW_NUMBER() OVER (' . $order . ') AS opis_rownum';
        $sql .= ' FROM ';
        $sql .= $this->handleTables($select->getTables());
        $sql .= $this->handleJoins($select->getJoins());
        $sql .= $this->handleWheres($select->getWheres());
        $sql .= $this->handleGroupings($select->getGroupBy());
        $sql .= $this->handleHavings($select->getHaving());

        $limit += $offset;
        $offset++;

        return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
    }