source/Setup/Database.php
public function parseQuery($sSQL)
    {
        // parses query into single pieces
        $aRet = [];
        $blComment = false;
        $blQuote = false;
        $sThisSQL = "";

        $aLines = explode("\n", $sSQL);

        // parse it
        foreach ($aLines as $sLine) {
            $iLen = strlen($sLine);
            for ($i = 0; $i < $iLen; $i++) {
                if (!$blQuote && ($sLine[$i] == '#' || ($sLine[0] == '-' && $sLine[1] == '-'))) {
                    $blComment = true;
                }

                // add this char to current command
                if (!$blComment) {
                    $sThisSQL .= $sLine[$i];
                }

                // test if quote on
                if (($sLine[$i] == '\'' && $sLine[$i - 1] != '\\')) {
                    $blQuote = !$blQuote; // toggle
                }

                // now test if command end is reached
                if (!$blQuote && $sLine[$i] == ';') {
                    // add this
                    $sThisSQL = trim($sThisSQL);
                    if ($sThisSQL) {
                        $sThisSQL = str_replace("\r", "", $sThisSQL);
                        $aRet[] = $sThisSQL;
                    }
                    $sThisSQL = "";
                }
            }
            // comments and quotes can't run over newlines
            $blComment = false;
            $blQuote = false;
        }

        return $aRet;
    }
public function parseQuery($sSQL)
    {
        // parses query into single pieces
        $aRet = [];
        $blComment = false;
        $blQuote = false;
        $sThisSQL = "";

        $aLines = explode("\n", $sSQL);

        // parse it
        foreach ($aLines as $sLine) {
            $iLen = strlen($sLine);
            for ($i = 0; $i < $iLen; $i++) {
                if (!$blQuote && ($sLine[$i] == '#' || ($sLine[0] == '-' && $sLine[1] == '-'))) {
                    $blComment = true;
                }

                // add this char to current command
                if (!$blComment) {
                    $sThisSQL .= $sLine[$i];
                }

                // test if quote on
                if (($sLine[$i] == '\'' && $sLine[$i - 1] != '\\')) {
                    $blQuote = !$blQuote; // toggle
                }

                // now test if command end is reached
                if (!$blQuote && $sLine[$i] == ';') {
                    // add this
                    $sThisSQL = trim($sThisSQL);
                    if ($sThisSQL) {
                        $sThisSQL = str_replace("\r", "", $sThisSQL);
                        $aRet[] = $sThisSQL;
                    }
                    $sThisSQL = "";
                }
            }
            // comments and quotes can't run over newlines
            $blComment = false;
            $blQuote = false;
        }

        return $aRet;
    }
public function parseQuery ( $ sSQL ) { // parses query into single pieces $ aRet = [ ] ; $ blComment = false ; $ blQuote = false ; $ sThisSQL = "" ; $ aLines = explode ( "\n" , $ sSQL ) ; // parse it foreach ( $ aLines as $ sLine ) { $ iLen = strlen ( $ sLine ) ; for ( $ i = 0 ; $ i < $ iLen ; $ i ++ ) { if ( ! $ blQuote && ( $ sLine [ $ i ] == '#' || ( $ sLine [ 0 ] == '-' && $ sLine [ 1 ] == '-' ) ) ) { $ blComment = true ; } // add this char to current command if ( ! $ blComment ) { $ sThisSQL .= $ sLine [ $ i ] ; } // test if quote on if ( ( $ sLine [ $ i ] == '\'' && $ sLine [ $ i - 1 ] != '\\' ) ) { $ blQuote = ! $ blQuote ; // toggle } // now test if command end is reached if ( ! $ blQuote && $ sLine [ $ i ] == ';' ) { // add this $ sThisSQL = trim ( $ sThisSQL ) ; if ( $ sThisSQL ) { $ sThisSQL = str_replace ( "\r" , "" , $ sThisSQL ) ; $ aRet [ ] = $ sThisSQL ; } $ sThisSQL = "" ; } } // comments and quotes can't run over newlines $ blComment = false ; $ blQuote = false ; } return $ aRet ; }
Parses query string into sql sentences

@param string $sSQL query string (usually reqd from *.sql file)

@return array
Parses query string into sql sentences