Even speedier version (at least 15 times faster) of split_sql_file(). wheeeeee.

git-svn-id: file:///svn/phpbb/trunk@1072 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
natec 2001-09-24 21:50:04 +00:00
parent 0fd5f22a8e
commit cdc1597550

View file

@ -101,7 +101,8 @@ function split_sql_file($sql, $delimiter)
{
// Split up our string into "possible" SQL statements.
$tokens = explode($delimiter, $sql);
// try to save memory.
// try to save mem.
$sql = "";
$output = array();
@ -133,11 +134,51 @@ function split_sql_file($sql, $delimiter)
}
else
{
// it's not complete, so prepend it onto the next token and continue the loop as usual.
$tokens[$i + 1] = $tokens[$i] . $delimiter . $tokens[$i + 1];
// save memory.
// incomplete sql statement. keep adding tokens until we have a complete one.
// $temp will hold what we have so far.
$temp = $tokens[$i] . $delimiter;
// save memory..
$tokens[$i] = "";
}
// Do we have a complete statement yet?
$complete_stmt = false;
for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means they're escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
if (($unescaped_quotes % 2) == 1)
{
// odd number of unescaped quotes. In combination with the previous incomplete
// statement(s), we now have a complete statement. (2 odds always make an even)
$output[] = $temp . $tokens[$j];
// save memory.
$tokens[$j] = "";
$temp = "";
// exit the loop.
$complete_stmt = true;
// make sure the outer loop continues at the right point.
$i = $j;
}
else
{
// even number of unescaped quotes. We still don't have a complete statement.
// (1 odd and 1 even always make an odd)
$temp .= $tokens[$j] . $delimiter;
// save memory.
$tokens[$j] = "";
}
} // for..
} // else
}
}