mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
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:
parent
0fd5f22a8e
commit
cdc1597550
1 changed files with 46 additions and 5 deletions
|
@ -101,7 +101,8 @@ function split_sql_file($sql, $delimiter)
|
||||||
{
|
{
|
||||||
// Split up our string into "possible" SQL statements.
|
// Split up our string into "possible" SQL statements.
|
||||||
$tokens = explode($delimiter, $sql);
|
$tokens = explode($delimiter, $sql);
|
||||||
// try to save memory.
|
|
||||||
|
// try to save mem.
|
||||||
$sql = "";
|
$sql = "";
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
|
@ -133,11 +134,51 @@ function split_sql_file($sql, $delimiter)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// it's not complete, so prepend it onto the next token and continue the loop as usual.
|
// incomplete sql statement. keep adding tokens until we have a complete one.
|
||||||
$tokens[$i + 1] = $tokens[$i] . $delimiter . $tokens[$i + 1];
|
// $temp will hold what we have so far.
|
||||||
// save memory.
|
$temp = $tokens[$i] . $delimiter;
|
||||||
|
// save memory..
|
||||||
$tokens[$i] = "";
|
$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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue