Replaces variable length placeholders with the real number of placeholder.

@param string  $statement
@param mixed[] $parameters

@throws OperationException

@return string
496375
private function expandPlaceholders($statement, array $parameters)
    {
        $index = 0;

        return preg_replace_callback(
            '/[\.]{3}\?|\?/',
            function ($match) use (&$index, &$statement, &$parameters) {
                if ($match[0] != '...?') {
                    ++$index;

                    return $match[0];
                }

                if (!is_array($parameters[$index]) || count($parameters[$index]) == 0) {
                    throw new OperationException(
                        sprintf(
                            'Variable length parameter %d is not an array.',
                            $index
                        ),
                        $statement
                    );
                }

                $result = implode(',', array_fill(0, count($parameters[$index]), '?'));

                ++$index;

                return $result;
            },
            $statement
        );
    }
758537
public function prepare($statement) {
        $this->connect();

        $this->statement = new Statement($statement, $this->getParams(), $this->routings);
        $this->statement->setFetchMode($this->defaultFetchMode);

        return $this->statement;
    }
854194
public function recv($statement, array $parameters = array(), $tag = null)
    {
        $runResponse = new Response();
        $r = $this->unpacker->unpack();
        $shouldThrow = false;
        if ($r->isFailure()) {
            try {
                $runResponse->onFailure($r);
            } catch (MessageFailureException $e) {
                // server ignores the PULL ALL
                $this->handleIgnore();
                $this->handleIgnore();
                $this->sendMessage(new AckFailureMessage());
                $this->handleIgnore();
                // server success for ACK FAILURE
                $r2 = $this->handleSuccess();
                $shouldThrow = $e;
            }
        }

        if ($shouldThrow !== false) {
            throw $shouldThrow;
        }

        if ($r->isSuccess()) {
            $runResponse->onSuccess($r);
        }

        $pullResponse = new Response();

        while (!$pullResponse->isCompleted()) {
            $r = $this->unpacker->unpack();

            if ($r->isRecord()) {
                $pullResponse->onRecord($r);
            }

            if ($r->isSuccess()) {
                $pullResponse->onSuccess($r);
            }
        }

        $cypherResult = new CypherResult(Statement::create($statement, $parameters, $tag));
        $cypherResult->setFields($runResponse->getMetadata()[0]->getElements());

        foreach ($pullResponse->getRecords() as $record) {
            $cypherResult->pushRecord($record);
        }

        if (null !== $pullResponse && array_key_exists(0, $pullResponse->getMetadata())) {
            $metadata = $pullResponse->getMetadata()[0]->getElements();
            $stats = array_key_exists('stats', $metadata) ? $metadata['stats'] : array();
            $cypherResult->setStatistics($stats);
        }

        return $cypherResult;
    }
1126088
protected function replacePatternParameterWithPlaceholder( $matches, &$parameters ) {
		$name = $matches['name'];
		$optional = ! empty( $matches['optional'] );

		$replacement = '/(?P<' . $name . '>' . $this->parameter_pattern . ')';

		if ( $optional ) {
			$replacement = '(?:' . $replacement . ')?';
		}

		$hash = sha1( implode( '_', [
			count( $parameters ),
			$replacement,
			uniqid( 'wpemerge_', true ),
		] ) );
		$placeholder = '___placeholder_' . $hash . '___';
		$parameters[ $placeholder ] = $replacement;

		return $placeholder;
	}
171671
public function prepare($statement, $options = null)
    {
        $options = is_null($options) ? [] : $options;
        if (strpos($statement, ':') !== false) {
            $i = 0;
            $bindKeyMap = [];
            $statement = preg_replace_callback('/:([a-zA-Z_]\w*?)\b/', function ($matches) use (&$i, &$bindKeyMap) {
                $bindKeyMap[$matches[1]] = $i++;

                return '?';
            }, $statement);
        }

        $stmtObj = $this->client->prepare($statement);

        if ($stmtObj) {
            $stmtObj->bindKeyMap = $bindKeyMap ?? [];

            return new PDOStatement($this, $stmtObj, $options);
        } else {
            $statementException = new StatementException($this->client->error, $this->client->errno);
            throw new QueryException($statement, [], $statementException);
        }
    }
1121894
public function execute($statement, array $bind = [])
    {
        $stmt = $this->query($statement, $bind);
        return $stmt->rowCount();
    }
195964
public function query_statement( Statement $statement, array $data, $options = 0 ) {

		$query = call_user_func_array(
			[ $this->wpdb, 'prepare' ],
			array_merge( [ (string) $statement] , $data )
		);
		$result               = $this->query( $query );
		$this->last_statement = $statement;

		return $result;
	}
1075332
private function _prepareStatement($sqlQueryString, $options)
    {
        $statementNum = 0;
        foreach ($options as $placeholder => $value) {
            if (is_object($value) && ($value instanceof SQLArgs || $value instanceof SQLArgsArray)) {
                $args = $value->toArray();

                if (!is_array($args)) {
                    $this->_error(FQDBException::INTERNAL_ASSERTION_FAIL, FQDBException::FQDB_CODE);
                }

                $statementNum++;
                $valueInStatementNum = 0;
                $whereInStatement = [];
                foreach ($args as $inStatementValue) {
                    $valueInStatementNum++;
                    $whereInStatement[':where_in_statement_' . $statementNum . '_' . $valueInStatementNum] = $inStatementValue;
                }

                $sqlQueryString = str_replace($placeholder, implode(', ', array_keys($whereInStatement)), $sqlQueryString);

                $options = array_merge($options, $whereInStatement);

                unset($options[$placeholder]);
            }
        }

        return [
            $sqlQueryString,
            $options
        ];
    }
207431
public function where($statement, $params = null)
    {
        $this->where[] = $statement;
        $this->addParams($params);

        return $this;
    }
184426
public function exists(string $statement, ...$params): bool
    {
        /**
         * @var string|int|float|bool|null $result
         */
        $result = $this->single($statement, $params);
        return !empty($result);
    }
320768
public static function bindToStatement(PDOStatement $statement, array $bindings=[])
    {
        foreach ($bindings as $key=>$value) {

            $casted = is_bool($value) ? (int)$value : $value;

            $statement->bindValue(
                is_string($key) ? $key : $key + 1,
                $casted,
                is_int($casted) ? PDO::PARAM_INT : ($casted === null ? PDO::PARAM_NULL : PDO::PARAM_STR)
            );

        }
    }
154072
private function getInsertStatement($usePlaceholders = true)
    {
        $statement = "";

        if (!$this->isInsert()) {
            return $statement;
        }

        $statement .= $this->getInsertString();

        if ($this->isInto) {
            $statement .= " " . $this->getIntoString($usePlaceholders);
        } else {
            if ($this->set) {
                $statement .= " " . $this->getSetString($usePlaceholders);
            }
        }
        return $statement;
    }
1267916
private function prepareStatement($query, $parameters) {
            $stmt = $this->db_connection->prepare($query);

            if (!empty($parameters)) {
                foreach ($parameters as $key => $val) {
                    $stmt->bindValue($key, $val);
                }
            }

            return $stmt;
        }
335114
protected function _executeStatement($statement, $sql, $params) {
        if ((!$statement->execute($params))) {
            throw new DbException($this->_pdoObject->errorInfo(), $sql, $params, $this->_errorReporting);
        }

        if ($statement->errorCode() == '00000') {
            return;
        }
        throw new DbException($statement->errorInfo(), $sql, $params, $this->_errorReporting);
    }
1031090
public function execute_statement( Statement $statement, array $data, $options = 0 ) {

		$this->query_statement( $statement, $data, $options );

		return $this->last_affected_rows();
	}
1059063
public function prepare(string $statement) : PreparedStatementInterface
    {
        try {
            $preparedStatement = $this->getConnection()->prepare($statement);
            return new PdoPreparedStatement($preparedStatement);
        } catch (\PDOException $e) {
            throw new ParserRuntimeException('Statement could not be prepared.', 0, $e);
        }
    }
869991
public function prepare($statement)
    {
        try {
            $stmt = new Statement($statement, $this);
        } catch (Throwable $ex) {
            throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
        }

        $stmt->setFetchMode($this->defaultFetchMode);

        return $stmt;
    }