diff options
author | natec <natec@users.sourceforge.net> | 2001-09-24 21:50:04 +0000 |
---|---|---|
committer | natec <natec@users.sourceforge.net> | 2001-09-24 21:50:04 +0000 |
commit | cdc1597550cd76aecf67c1f6d254e398a1cb8396 (patch) | |
tree | 97bd558e61c630348084d35d2e220f9f8f5ef969 /phpBB/includes/sql_parse.php | |
parent | 0fd5f22a8e3054095d82fdd2acd938450497986f (diff) | |
download | forums-cdc1597550cd76aecf67c1f6d254e398a1cb8396.tar forums-cdc1597550cd76aecf67c1f6d254e398a1cb8396.tar.gz forums-cdc1597550cd76aecf67c1f6d254e398a1cb8396.tar.bz2 forums-cdc1597550cd76aecf67c1f6d254e398a1cb8396.tar.xz forums-cdc1597550cd76aecf67c1f6d254e398a1cb8396.zip |
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
Diffstat (limited to 'phpBB/includes/sql_parse.php')
-rw-r--r-- | phpBB/includes/sql_parse.php | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/phpBB/includes/sql_parse.php b/phpBB/includes/sql_parse.php index dcb0482e04..8f8a52b8f9 100644 --- a/phpBB/includes/sql_parse.php +++ b/phpBB/includes/sql_parse.php @@ -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 } } |