classes/phing/tasks/ext/pdo/DefaultPDOQuerySplitter.php
public function nextQuery()
    {
        $sql = "";
        $hasQuery = false;

        while (($line = $this->sqlReader->readLine()) !== null) {
            $delimiter = $this->parent->getDelimiter();
            $project = $this->parent->getOwningTarget()->getProject();
            $line = $project->replaceProperties(trim($line));

            if (($line != $delimiter) && (StringHelper::startsWith("//", $line)
                    || StringHelper::startsWith("--", $line)
                    || StringHelper::startsWith("#", $line))
            ) {
                continue;
            }

            if (strlen($line) > 4
                && strtoupper(substr($line, 0, 4)) == "REM "
            ) {
                continue;
            }

            // MySQL supports defining new delimiters
            if (preg_match('/DELIMITER [\'"]?([^\'" $]+)[\'"]?/i', $line, $matches)) {
                $this->parent->setDelimiter($matches[1]);
                continue;
            }

            if ($this->sqlBacklog !== "") {
                $sql = $this->sqlBacklog;
                $this->sqlBacklog = "";
            }

            $sql .= " " . $line . "\n";

            // SQL defines "--" as a comment to EOL
            // and in Oracle it may contain a hint
            // so we cannot just remove it, instead we must end it
            if (strpos($line, "--") !== false) {
                $sql .= "\n";
            }

            // DELIM_ROW doesn't need this (as far as i can tell)
            if ($this->delimiterType == PDOSQLExecTask::DELIM_NORMAL) {
                $reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($delimiter) . ")#";

                $sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
                $this->sqlBacklog = "";
                foreach ($sqlParts as $sqlPart) {
                    // we always want to append, even if it's a delim (which will be stripped off later)
                    $this->sqlBacklog .= $sqlPart;

                    // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                    if ($sqlPart === $delimiter) {
                        $sql = $this->sqlBacklog;
                        $this->sqlBacklog = "";
                        $hasQuery = true;
                    }
                }
            }

            if ($hasQuery || ($this->delimiterType == PDOSQLExecTask::DELIM_ROW && $line == $delimiter)) {
                // this assumes there is always a delimter on the end of the SQL statement.
                $sql = StringHelper::substring(
                    $sql,
                    0,
                    strlen($sql) - strlen($delimiter)
                    - ($this->delimiterType == PDOSQLExecTask::DELIM_ROW ? 2 : 1)
                );

                return $sql;
            }
        }

        // Catch any statements not followed by ;
        if ($sql !== "") {
            return $sql;
        }

        return null;
    }
public function nextQuery()
    {
        $sql = "";
        $hasQuery = false;

        while (($line = $this->sqlReader->readLine()) !== null) {
            $delimiter = $this->parent->getDelimiter();
            $project = $this->parent->getOwningTarget()->getProject();
            $line = $project->replaceProperties(trim($line));

            if (($line != $delimiter) && (StringHelper::startsWith("//", $line)
                    || StringHelper::startsWith("--", $line)
                    || StringHelper::startsWith("#", $line))
            ) {
                continue;
            }

            if (strlen($line) > 4
                && strtoupper(substr($line, 0, 4)) == "REM "
            ) {
                continue;
            }

            // MySQL supports defining new delimiters
            if (preg_match('/DELIMITER [\'"]?([^\'" $]+)[\'"]?/i', $line, $matches)) {
                $this->parent->setDelimiter($matches[1]);
                continue;
            }

            if ($this->sqlBacklog !== "") {
                $sql = $this->sqlBacklog;
                $this->sqlBacklog = "";
            }

            $sql .= " " . $line . "\n";

            // SQL defines "--" as a comment to EOL
            // and in Oracle it may contain a hint
            // so we cannot just remove it, instead we must end it
            if (strpos($line, "--") !== false) {
                $sql .= "\n";
            }

            // DELIM_ROW doesn't need this (as far as i can tell)
            if ($this->delimiterType == PDOSQLExecTask::DELIM_NORMAL) {
                $reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($delimiter) . ")#";

                $sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
                $this->sqlBacklog = "";
                foreach ($sqlParts as $sqlPart) {
                    // we always want to append, even if it's a delim (which will be stripped off later)
                    $this->sqlBacklog .= $sqlPart;

                    // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                    if ($sqlPart === $delimiter) {
                        $sql = $this->sqlBacklog;
                        $this->sqlBacklog = "";
                        $hasQuery = true;
                    }
                }
            }

            if ($hasQuery || ($this->delimiterType == PDOSQLExecTask::DELIM_ROW && $line == $delimiter)) {
                // this assumes there is always a delimter on the end of the SQL statement.
                $sql = StringHelper::substring(
                    $sql,
                    0,
                    strlen($sql) - strlen($delimiter)
                    - ($this->delimiterType == PDOSQLExecTask::DELIM_ROW ? 2 : 1)
                );

                return $sql;
            }
        }

        // Catch any statements not followed by ;
        if ($sql !== "") {
            return $sql;
        }

        return null;
    }
public function nextQuery ( ) { $ sql = "" ; $ hasQuery = false ; while ( ( $ line = $ this -> sqlReader -> readLine ( ) ) !== null ) { $ delimiter = $ this -> parent -> getDelimiter ( ) ; $ project = $ this -> parent -> getOwningTarget ( ) -> getProject ( ) ; $ line = $ project -> replaceProperties ( trim ( $ line ) ) ; if ( ( $ line != $ delimiter ) && ( StringHelper :: startsWith ( "//" , $ line ) || StringHelper :: startsWith ( "--" , $ line ) || StringHelper :: startsWith ( "#" , $ line ) ) ) { continue ; } if ( strlen ( $ line ) > 4 && strtoupper ( substr ( $ line , 0 , 4 ) ) == "REM " ) { continue ; } // MySQL supports defining new delimiters if ( preg_match ( '/DELIMITER [\'"]?([^\'" $]+)[\'"]?/i' , $ line , $ matches ) ) { $ this -> parent -> setDelimiter ( $ matches [ 1 ] ) ; continue ; } if ( $ this -> sqlBacklog !== "" ) { $ sql = $ this -> sqlBacklog ; $ this -> sqlBacklog = "" ; } $ sql .= " " . $ line . "\n" ; // SQL defines "--" as a comment to EOL // and in Oracle it may contain a hint // so we cannot just remove it, instead we must end it if ( strpos ( $ line , "--" ) !== false ) { $ sql .= "\n" ; } // DELIM_ROW doesn't need this (as far as i can tell) if ( $ this -> delimiterType == PDOSQLExecTask :: DELIM_NORMAL ) { $ reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote ( $ delimiter ) . ")#" ; $ sqlParts = preg_split ( $ reg , $ sql , 0 , PREG_SPLIT_DELIM_CAPTURE ) ; $ this -> sqlBacklog = "" ; foreach ( $ sqlParts as $ sqlPart ) { // we always want to append, even if it's a delim (which will be stripped off later) $ this -> sqlBacklog .= $ sqlPart ; // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query if ( $ sqlPart === $ delimiter ) { $ sql = $ this -> sqlBacklog ; $ this -> sqlBacklog = "" ; $ hasQuery = true ; } } } if ( $ hasQuery || ( $ this -> delimiterType == PDOSQLExecTask :: DELIM_ROW && $ line == $ delimiter ) ) { // this assumes there is always a delimter on the end of the SQL statement. $ sql = StringHelper :: substring ( $ sql , 0 , strlen ( $ sql ) - strlen ( $ delimiter ) - ( $ this -> delimiterType == PDOSQLExecTask :: DELIM_ROW ? 2 : 1 ) ) ; return $ sql ; } } // Catch any statements not followed by ; if ( $ sql !== "" ) { return $ sql ; } return null ; }
Returns next query from SQL source, null if no more queries left

In case of "row" delimiter type this searches for strings containing only
delimiters. In case of "normal" delimiter type, this uses simple regular
expression logic to search for delimiters.

@return string|null
Returns next query from SQL source null if no more queries left