private static function determinePlaceholderPosition($query, $index, array $placeholdersPositions = array())
    {
        // The placeholder position.
        $placeholderPosition = null;

        // Find the previous cached placeholder position in the stack to optimize the current placeholder position
        // search.

        // The previous parameter index cached.
        $previousIndex = $index - 1;

        // Iterate each cached placeholder positions to find the previous one & the previous parameter index.
        while (($previousIndex >= 0) && ($placeholderPosition === null)) {

            // Check if the previous cached placeholder positions exists.
            if (isset($placeholdersPositions[$previousIndex])) {
                $placeholderPosition = $placeholdersPositions[$previousIndex];
                $previousIndex++;
            } else {
                $previousIndex--;
            }
        }

        // Check if the previous placeholder position has been found.
        if ($placeholderPosition === null) {
            $previousIndex = 0;
            $placeholderPosition = 0;
        }

        // Determine the query length.
        $queryLength = strlen($query);

        // Iterate from the previous cached parameter index to the current one.
        for ($placeholderIndex = $previousIndex; $placeholderIndex <= $index; $placeholderIndex++) {

            // TRUE if we are in an escaped section else FALSE.
            $escaped = false;

            // Iterate each query char from the previous placeholder position to the end in order to find the current
            // placeholder.
            while ($placeholderPosition < $queryLength) {

                // Switch the escaped flag if the current statement char is an escape delimiter.
                if (in_array($query[$placeholderPosition], array('\'', '"'))) {
                    $escaped = !$escaped;
                }

                // Check if we are not in an escaped section and if the current char is a placeholder.
                if (!$escaped && ($query[$placeholderPosition] === '?')) {

                    // If we are not on the current placeholder, we increment the placeholder position.
                    if ($placeholderIndex < $index) {
                        $placeholderPosition++;
                    }

                    break;
                }

                $placeholderPosition++;
            }

            // Check if we have found the placeholder position.
            if ($placeholderPosition === $queryLength) {
                throw QueryRewriterException::positionalPlaceholderDoesNotExist($index, $query);
            }
        }

        return $placeholderPosition;
    }
private static function determinePlaceholderPosition($query, $index, array $placeholdersPositions = array())
    {
        // The placeholder position.
        $placeholderPosition = null;

        // Find the previous cached placeholder position in the stack to optimize the current placeholder position
        // search.

        // The previous parameter index cached.
        $previousIndex = $index - 1;

        // Iterate each cached placeholder positions to find the previous one & the previous parameter index.
        while (($previousIndex >= 0) && ($placeholderPosition === null)) {

            // Check if the previous cached placeholder positions exists.
            if (isset($placeholdersPositions[$previousIndex])) {
                $placeholderPosition = $placeholdersPositions[$previousIndex];
                $previousIndex++;
            } else {
                $previousIndex--;
            }
        }

        // Check if the previous placeholder position has been found.
        if ($placeholderPosition === null) {
            $previousIndex = 0;
            $placeholderPosition = 0;
        }

        // Determine the query length.
        $queryLength = strlen($query);

        // Iterate from the previous cached parameter index to the current one.
        for ($placeholderIndex = $previousIndex; $placeholderIndex <= $index; $placeholderIndex++) {

            // TRUE if we are in an escaped section else FALSE.
            $escaped = false;

            // Iterate each query char from the previous placeholder position to the end in order to find the current
            // placeholder.
            while ($placeholderPosition < $queryLength) {

                // Switch the escaped flag if the current statement char is an escape delimiter.
                if (in_array($query[$placeholderPosition], array('\'', '"'))) {
                    $escaped = !$escaped;
                }

                // Check if we are not in an escaped section and if the current char is a placeholder.
                if (!$escaped && ($query[$placeholderPosition] === '?')) {

                    // If we are not on the current placeholder, we increment the placeholder position.
                    if ($placeholderIndex < $index) {
                        $placeholderPosition++;
                    }

                    break;
                }

                $placeholderPosition++;
            }

            // Check if we have found the placeholder position.
            if ($placeholderPosition === $queryLength) {
                throw QueryRewriterException::positionalPlaceholderDoesNotExist($index, $query);
            }
        }

        return $placeholderPosition;
    }
private static function determinePlaceholderPosition ( $ query , $ index , array $ placeholdersPositions = array ( ) ) { // The placeholder position. $ placeholderPosition = null ; // Find the previous cached placeholder position in the stack to optimize the current placeholder position // search. // The previous parameter index cached. $ previousIndex = $ index - 1 ; // Iterate each cached placeholder positions to find the previous one & the previous parameter index. while ( ( $ previousIndex >= 0 ) && ( $ placeholderPosition === null ) ) { // Check if the previous cached placeholder positions exists. if ( isset ( $ placeholdersPositions [ $ previousIndex ] ) ) { $ placeholderPosition = $ placeholdersPositions [ $ previousIndex ] ; $ previousIndex ++ ; } else { $ previousIndex -- ; } } // Check if the previous placeholder position has been found. if ( $ placeholderPosition === null ) { $ previousIndex = 0 ; $ placeholderPosition = 0 ; } // Determine the query length. $ queryLength = strlen ( $ query ) ; // Iterate from the previous cached parameter index to the current one. for ( $ placeholderIndex = $ previousIndex ; $ placeholderIndex <= $ index ; $ placeholderIndex ++ ) { // TRUE if we are in an escaped section else FALSE. $ escaped = false ; // Iterate each query char from the previous placeholder position to the end in order to find the current // placeholder. while ( $ placeholderPosition < $ queryLength ) { // Switch the escaped flag if the current statement char is an escape delimiter. if ( in_array ( $ query [ $ placeholderPosition ] , array ( '\'' , '"' ) ) ) { $ escaped = ! $ escaped ; } // Check if we are not in an escaped section and if the current char is a placeholder. if ( ! $ escaped && ( $ query [ $ placeholderPosition ] === '?' ) ) { // If we are not on the current placeholder, we increment the placeholder position. if ( $ placeholderIndex < $ index ) { $ placeholderPosition ++ ; } break ; } $ placeholderPosition ++ ; } // Check if we have found the placeholder position. if ( $ placeholderPosition === $ queryLength ) { throw QueryRewriterException :: positionalPlaceholderDoesNotExist ( $ index , $ query ) ; } } return $ placeholderPosition ; }
Determines the placeholder position in the query.

Example:
- parameters:
- query: SELECT * FROM foo WHERE foo IN (?) AND bar IN (?)
^ (33)        ^ (47)
- index: 1
- cachedPlaceholdersPositions: array(33)
- result:
- placeholderPosition: 47

@param string  $query                 The query.
@param integer $index                 The query parameter index (indexed by 0).
@param array   $placeholdersPositions The cached placeholders positions.

@throws \Fridge\DBAL\Exception\QueryRewriterException If the placeholder does not exist.

@return integer The placeholder position.
Determines the placeholder position in the query .